Oct-19-2021, 04:18 PM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
from fastai import * from fastai.text import * from fastai.vision import * import pandas as pd import numpy as np df = pd.read_csv( 'all_ml_ideas.csv' , header = None , names = [ 'idea' ]) df[ 'idea' ] = df[ 'idea' ]. str .lower() df.head() valid_pct = 0.05 #validation percent df = df.iloc[np.random.permutation( len (df))] cut = int (valid_pct * len (df)) + 1 train_df, valid_df = df[cut:], df[:cut] len (df) len (train_df) len (valid_df) nan_rows = df[df[ 'idea' ].isnull()] nan_rows data_lm = TextLMDataBunch.from_df( 'data' , train_df, valid_df, text_cols = 'idea' ) #data_clas = TextClasDataBunch.from_df('data', train_df, valid_df, text_cols='text', label_cols='author', vocab=data_lm.train_ds.vocab, bs=32) learn = language_model_learner(data_lm, pretrained_model = URLs.WT103, drop_mult = 0.5 ) learn.fit_one_cycle( 1 , 1e - 2 ) learn.unfreeze() learn.fit_one_cycle( 1 , 1e - 3 ) wd = 1e - 7 lr = 1e - 3 lrs = lr learn.fit( 15 ,lrs, wd) number_of_ideas = 100 ideas_counter = 0 all_ideas = [] for i in range ( 100 ): idea = learn.predict( "xxbos xxfld 1" , n_words = 20 , temperature = 0.8 ) ideas = idea.split( "xxbos xxfld 1" ) ideas = ideas[ 1 : - 1 ] for idea in ideas: idea = idea.replace( "xxbos xxfld 1 " ,"").strip() if (idea): all_ideas.append(idea) ideas_counter = ideas_counter + 1 if ideas_counter > number_of_ideas: break all_ideas learn.save_encoder( 'ml_ft_enc' ) train_df.to_pickle( 'data/ml_train_df.pkl' ) valid_df.to_pickle( 'data/ml_valid_df.pkl' ) |
Error:NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13128/2953327316.py in <module>
29 nan_rows
30
---> 31 data_lm = TextLMDataBunch.from_df('data', train_df, valid_df, text_cols='idea')
32
33 #data_clas = TextClasDataBunch.from_df('data', train_df, valid_df, text_cols='text', label_cols='author', vocab=data_lm.train_ds.vocab, bs=32)
NameError: name 'TextLMDataBunch' is not defined
I have tried two things that I saw on line.1. Use fastai v1 in program
2. put from fastai.vision import * in import file area.
neither one will work.
I am at a loss to find a way to correct this error.
Any help appreciated.
Respectfully,
LZ