TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #32 · 7 фев.

Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять: from timeit import timeit def t1(): # складываем 10 строк через + из переменной t = 'text' for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t2(): # склеиваем список строк через метод join arr = ['text'] * 10 for _ in range(1000): s = ''.join(arr) def t3(): # складываем через + но не из переменной а непосредственно инлайн объекты for _ in range(1000): s = 'text' + 'text' + 'text' + ... # всего 10 раз Теперь каждую строку склейки запустим по 10М раз >>> timeit(t1, number=10000) 0.21951690399964718 >>> timeit(t2, number=10000) 1.4978306379998685 >>> timeit(t3, number=10000) 0.2213820789993406 Хм, а нам говорили что через "+" это плохо и медленно ))) 😁 Тут стоит учитывать, что речь идёт о склейке множества длинных строк. Давайте изменим условия: def t4(): t = 'text'*100 for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t5(): arr = ['text'*100] * 10 for _ in range(1000): s = ''.join(arr) def t6(): for _ in range(1000): s = 'text'*100 + 'text'*100 + ... # всего 10 раз >>> timeit(t4, number=10000) 12.795130728000004 >>> timeit(t5, number=10000) 2.642637542999182 >>> timeit(t6, number=10000) 0.2184546610005782 Вот, уже другой разговор, сразу видна разница, в среднем в 6 раз. Но погодите, почему последний тест t6() по скорости такой же как и t3()? Ведь строки теперь в 100 раз длиннее! Это вопросы оптимизации кода, какие простые изменения ускоряют или замедляют выполнение программы. Мы столкнулись с примером обхода обращения к переменной. Например, именно так работает директива #define в С++, во время компиляции подставляя значение переменной вместо ссылки на неё. В Python это тоже работает, но часто ли вы сможете встретить такой способ работы со строками? К сожалению, способ почти только теоретический. В целом, тесты показали то, что мы хотели. Делаем выводы самостоятельно. Полный листинг 🌍 #tricks

Резултати

Пронајдени 3 слични објави

Пребарај: #aiandsociety

当前筛选 #aiandsociety清除筛选
AI & Law

@ai_and_law · Post #84 · 15.08.2023 г., 07:04

House of Lords Deliberates Advanced AI: UK's Ongoing AI Debate Hello, everyone! The UK House of Lords recently engaged in a discussion about advanced AI's ongoing development, addressing potential risks and regulatory strategies. The debate focused on whether the government's March White Paper on AI regulation is still relevant or if new legislation is necessary due to recent developments. The House of Lords' discussion underscores the complexities of overseeing rapidly evolving AI technologies, showcasing the government's dedication to fostering AI innovation while prioritizing public safety and responsible development. #AIRegulation#AIandLaw#AIandSociety

AI & Law

@ai_and_law · Post #438 · 08.11.2024 г., 08:04

Navigating AI Governance in a New Era: Key Insights from the World Economic Forum The World Economic Forum’s report, "Governance in the Age of Generative AI," emphasizes that effective governance of generative AI requires timely and strategic assessments of regulatory frameworks, industry responsibilities, and human rights considerations. To harness AI responsibly, policymakers need to evaluate whether existing laws and regulations meet the distinct risks posed by generative AI. This includes ensuring that protections are in place for vulnerable groups and aligning with international human rights standards. The report also stresses the importance of balancing regulatory caution with the need for innovation. Governments are encouraged to adopt risk-based, agile governance that leverages tech-like dynamism but avoids compromising oversight or human rights. Ultimately, the goal is to foster an AI landscape that supports both public interest and economic innovation through robust risk management, clarified policies, and sustained industry alignment with societal values. #AIGovernance#WEFReport#ResponsibleAI#AIandSociety

AI & Law

@ai_and_law · Post #206 · 04.01.2024 г., 08:04

AI Image-Generators Trained on Explicit Photos of Children Hello everyone! A startling revelation demands immediate attention: popular AI image-generators harbor a concerning flaw, with thousands of explicit images of child abuse embedded in their foundations. This revelation comes from a recent report by the Stanford Internet Observatory, urging swift action to address this deeply troubling aspect of the technology. Hidden within the colossal AI database LAION, a fundamental resource for training leading AI image-making models, are over 3,200 images of suspected child sexual abuse. The watchdog group, in collaboration with anti-abuse charities, brought this disturbing fact to light, emphasizing the urgency for companies to rectify this issue. The material influences AI tools to generate harmful outputs, potentially perpetuating the exploitation of real victims. In response to the report, LAION, an acronym for the Large-scale Artificial Intelligence Open Network, has promptly taken down its datasets, emphasizing a zero-tolerance policy for illegal content. However, this incident underscores broader challenges in the rush to make AI tools accessible, raising questions about the responsibility of developers and platforms in ensuring the ethical use of such technology. The Stanford report calls for decisive measures, including the deletion of training sets derived from LAION and making certain AI models, particularly an older version of Stable Diffusion, less accessible. The report also emphasizes the need for comprehensive filters and collaboration with child safety experts in developing AI datasets. #AILaw#AIethics#AIGeneration#StanfordReport#AIandSociety