Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot correct this
#1
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
Reply
#2
Where is the class supposed to come from? Have you checked the documentation for the library to see whether you've got the class name correct and that you're importing the right package? Make sure you check the docs for the version you're using, as perhaps things moved between versions.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020