Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import the encoder code for fine tuning GPT-2

I'm trying to reproduce the example from this article: https://medium.com/@ngwaifoong92/beginners-guide-to-retrain-gpt-2-117m-to-generate-custom-text-content-8bb5363d8b7f

The example code is from the following repo: https://github.com/nshepperd/gpt-2

After installing the requirements and downloading the model, the following step is to train the model, for which this code has to be executed:

python encode.py lyric.txt lyric.npz

The issue here is that this requires to import the following modules:

import argparse
import numpy as np

import encoder
from load_dataset import load_dataset

Where encoder and load_dataset are on a child directory:

|--encode.py
 --src
   |--encoder.py
   |--load_dataset.py

This generates the following error:

ModuleNotFoundError: No module named 'encoder'

I tried creating the __init__.py files and importing them as

src.encoder and src.load_dataset but that those not work either.

In the medium post the author proposes to move the file encoder.py to src and execute the code from there, the issue there is that doing it breaks the relative path for the model too and although I handled that the issue with the paths keeps going for other files as well.

like image 480
Luis Ramon Ramirez Rodriguez Avatar asked Jan 01 '26 03:01

Luis Ramon Ramirez Rodriguez


1 Answers

  1. Make an empty file named __init__.py inside the src folder.
  2. Import encoder as:from src import encoder
like image 116
0x5050 Avatar answered Jan 03 '26 15:01

0x5050



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!