Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to run a tested model with Win10+Anaconda3

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to run a tested model with Win10+Anaconda3". In daily operation, I believe that many people have doubts about how to run a tested model with Win10+Anaconda3. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to run a tested model with Win10+Anaconda3". Next, please follow the editor to study!

1. The local machine already has an environment before installation

Win10,Pycharm 2020.3 (this does not have to be the same as the version, just support python3.6)

2. Newly installed

Pytorch,transformer

III. Concrete steps

1. Configure the environment (all in cmd)

Install Anaconda3, open cmd, enter the following instructions to make sure that Anaconda3 has been installed, showing that the conda version has been installed. If there is a mistake, go to the Internet to find a solution, mostly because the environment variables have not been added well.

Conda-version

Here we create a new virtual environment, and it is highly recommended to do this in the future, so that no matter what version of python you want to install, you do not have to rely on other environments, which is very convenient.

First enter the following command, which will appear in the existing virtual environment, and if you haven't created it before, there should be only one environment. Like me, it shows the environment I already have.

Conda info-envs

To create a new virtual environment, enter the following instructions, which means to create a virtual environment called "project" with pyhton version 3.6. Wait patiently for the installation to complete.

Conda create-name project python=3.6

Enter the following command again to ensure that the new environment is added.

Conda info-envs

Enter the following instructions to activate the environment and check that the python version is 3.6. The activation environment is represented by the name of the environment at the front of the input command line, as shown in the figure

Activate project / / activate environment python-- version / / check python version

The rest of the operation is in this environment, so do not exit, but here is the instruction to exit the environment: deactivate.

Install pytorch

Pip install torch==1.5.1+cpu torchvision==0.6.1+cpu-f https://download.pytorch.org/whl/torch_stable.html

Install transformers after the installation is completed. Just follow my version directly.

Pip install transformers==2.1.1

Waiting for the installation to be successful, I did not report an error here, which has something to do with the python version. I suggest you follow my environmental parameters! If there is a mistake, check it patiently and find the answer.

Everything that needs to be installed is done. Proceed to the following steps.

2. Some operations

Download the source code, link: https://github.com/Morizeyao/GPT2-Chinese

Download the trained model, the author gives the download location in the link above, I try to run the general Chinese model.

Unzip the package and open the project with pycharm.

Put the downloaded model into the project, as shown in the following figure, and you can see that this is the structure of the author's organization in scripts/generate.sh.

3. Switch the engineering environment of pycharm

① opens pycharm file-> setting, the pop-up dialog box, the left side to find Project:GPT2-Chinese, open python interpreter, there is a setting icon on the right, click, click Add, ② select Existing environment, click the next three points, ③ select the envs under your installation of Anaconda3 in the previous test environment file we created in the python.exe, click OK. Wait a moment to make sure that pycharm supports this version of python. ④ then selects the environment we just added, waits for the system to respond for a while, and then runs the current project in the environment we created, which has pytorch and transformers~ installed.

When everything is done, open a terminal in pycharm and make sure it is preceded by the name of the environment we added ~ (my name here is project)

If this time shows that there are any packages not installed, you can click install should be able to download normally, transformers is the most difficult to download we have already downloaded.

This is the end of configuring the environment.

Fourth, generate the text

Here, I created a new text folder under the root directory to hold the txt text we generated.

Enter the following instructions in terminal to generate text, and the specific parameters are explained in detail in generate.py. A lot of details can be seen in the github Central Plains author's readme is very detailed.

Python. / generate.py-- length=50-- nsamples=4-- prefix= -- fast_pattern-- save_samples-- save_samples_path=./text / / prefix followed by [CLS] is the beginning of the text you want to generate

The following are five examples I generated at the beginning of "very happy today". The parameters can adjust the number of sentences and words generated.

At this point, the study on "how to run a tested model with Win10+Anaconda3" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report