21
loading...
This website collects cookies to deliver better user experience
Make a python file named utils.py
and start writing code. Let's first import the needed dependencies for the project
here we are importing transformers to load the model and the tokenizer from hugging face and also we are importing os to check if the model and tokenizer are already installed in the directory or not.
Then make a function named load_model
which will load the model and tokenizer. Both model and tokenizer are required to generate results.
Here the program will check if the tokenizer and model are installed in the system or not. When you run the program for the first time then it will download the model and tokenizer from humming face i.e cpierse/gpt2_film_scripts
and store them locally in the system so that next time you don't have to install it again. After that, it's simply returning the tokenizer and model.
After this, we will be making a function for generating the script.
In this function, we trained the model and now using model.generate()
we are getting the script. As you can see the model.generate() function takes max_length
and input_ids
which is nothing but the context of the initial script provided.
After this, create another python file and name it as main.py. Here add the following code.
In main.py
file, we are importing the load_model and generating functions from utils.py
and simply calling the functions to get the result.