日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

机器学习 对模型进行惩罚_使用Streamlit对机器学习模型进行原型制作

發布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 机器学习 对模型进行惩罚_使用Streamlit对机器学习模型进行原型制作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

機器學習 對模型進行懲罰

GitHub Repo: ml-streamlit-demo

GitHub存儲庫: ml-streamlit-demo

Bringing a Machine Learning model outside of a notebook environment and turning it into a beautiful data product used to be a lot of work. Luckily, there’s a lot of tooling being developed in this area to make prototyping easier. A while ago, I came across Streamlit, an open source Python library for building custom web apps.

將機器學習模型帶到筆記本環境之外,然后將其轉變為漂亮的數據產品,這過去需要做很多工作。 幸運的是,該領域正在開發許多工具,以簡化原型設計。 前一段時間,我遇到了Streamlit ,這是一個用于構建自定義Web應用程序的開源Python庫。

It’s quick and easy to get started and took me less than 30 minutes to build an app with a pre-trained model. Since then, I have been using Streamlit for prototyping models and demonstrating their capabilities. The nice user interface is a refreshing change from using my console for predictions.

它快速且容易上手,用了不到30分鐘的時間我就構建了具有預訓練模型的應用程序。 從那時起,我一直在使用Streamlit制作模型原型并展示其功能。 與使用我的控制臺進行預測相比,漂亮的用戶界面是一個令人耳目一新的變化。

I’m going to be sharing the process in this article, using GPT-2 as an example.

我將以GPT-2為例分享本文中的過程。

在本文中,我們將: (In this article, we will:)

  • load GPT-2 from HuggingFace’s transformer library

    從HuggingFace的變壓器庫中加載GPT-2

  • serve the text generator in a simple web app using Streamlit

    使用Streamlit在簡單的Web應用程序中提供文本生成器

從變形金剛加載GPT-2 (Load GPT-2 from Transformers)

GPT-2 is a transformers model trained on a very large English corpus for the purpose of predicting the next word in a phrase. It’s recent successor, GPT-3, have shocked the world with what it is capable of doing.

GPT-2是在非常大型的英語語料庫上訓練的變形模型,用于預測短語中的下一個單詞。 它最近的繼任者GPT-3 ,以其強大的功能震驚了世界。

Let’s begin by installing all of the Python prerequisites. This is what my requirements.txt looks like. While not referenced anywhere in the code, GPT-2 requires either TensorFlow 2.0 or PyTorch to be installed.

讓我們從安裝所有Python先決條件開始。 這就是我的requirements.txt樣子。 盡管代碼中未引用GPT-2,但需要安裝TensorFlow 2.0或PyTorch。

streamlit==0.56.0
tensorflow==2.2.0
transformers==3.0.2

In this example, we are going to work out of a single Python script. Here is the class for loading GPT-2 and using it to generate text when given a starting phrase. The max_length attribute indicates the max length of the generated text.

在此示例中,我們將使用單個Python腳本。 這是用于加載GPT-2并在給定起始短語時使用它生成文本的類。 max_length屬性指示生成的文本的最大長度。

通過Streamlit服務模型 (Serve the Model with Streamlit)

I’m going to define another function for instantiating the generator. The purpose of this function is to help with caching the load_generator method to make subsequent predictions faster.

我將定義另一個用于實例化生成器的函數。 此函數的目的是幫助緩存load_generator方法,以使后續預測更快。

The st.cache decorator tells Streamlit to skip execution if the function has been executed already.

如果函數已經執行,則st.cache裝飾器告訴Streamlit跳過執行。

The entry point for this file defines the layout for the UI.

該文件的入口點定義UI的布局。

快速演示 (A Quick Demo)

To start the app, run streamlit run filepath.py]. If you are using my repository, this would be streamlit run models/gpt_demo.py

要啟動該應用程序,請運行streamlit run filepath.py] 。 如果您使用的是我的存儲庫,則可以streamlit run models/gpt_demo.py

The app should be automatically launched in the browser. If not, it will be at http://localhost:8501/. After the generator is loaded, predictions should be much faster!

該應用程序應在瀏覽器中自動啟動。 如果不是,它將位于http:// localhost:8501 / 。 生成器加載后,預測應該快得多!

I haven’t used this yet, but if you click on the hamburger menu (3 horizontal lines in the top right corner), there is an option for recording your demo using Streamlit. Pretty neat.

我還沒有用過,但是如果您單擊漢堡菜單(右上角有3條水平線),則可以使用Streamlit錄制演示。 漂亮整齊。

讓GPT-2完成一些想法! (Let’s have GPT-2 finish some thoughts!)

我渴望... (I am craving …)

建立時間機器的秘訣... (The secret to building a time machine …)

And there you have it — a pretty web app built in under 5 minutes.

在那里,您可以在5分鐘之內構建一個漂亮的Web應用程序。

感謝您的閱讀! (Thank you for reading!)

If you enjoyed this article, check out my other articles on Data Science, Math and Programming. Follow me on Medium for the latest updates. 😃

如果您喜歡這篇文章,請查看我關于數據科學,數學和編程的其他文章。 按照我在Medium上的最新更新。 😃

I am also building a comprehensive set of free Data Science lessons and practice problems at www.dscrashcourse.com as a hobby project.

我還在業余愛好www.dscrashcourse.com上構建了一套全面的免費數據科學課程,并練習了問題。

If you want to support my writing, consider using my affiliate link the next time you sign up for a Coursera course. Full disclosure — I receive a commission for every enrollment, but it comes at no extra cost for you.

如果您想支持我的寫作,請在下次注冊Coursera課程時考慮使用“我的會員”鏈接 。 完全披露-每次注冊我都會獲得傭金,但這對您沒有任何額外費用。

Thank you again for reading! 📕

再次感謝您的閱讀! 📕

翻譯自: https://towardsdatascience.com/prototyping-machine-learning-models-with-streamlit-1134c34e9620

機器學習 對模型進行懲罰

總結

以上是生活随笔為你收集整理的机器学习 对模型进行惩罚_使用Streamlit对机器学习模型进行原型制作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。