Python Forum
no module named finbert found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
no module named finbert found
#1
The following code generates a error:

[/code]
from pathlib import Path
import sys
sys.path.append('..')
import argparse
import shutil
import os
import logging
from textblob import TextBlob

from pytorch_pretrained_bert.file_utils import PYTORCH_PRETRAINED_BERT_CACHE
from pytorch_pretrained_bert.modeling import BertForSequenceClassification
from pytorch_pretrained_bert.tokenization import BertTokenizer
from pytorch_pretrained_bert.optimization import *

from finbert.finbert import *
import finbert.utils as tools
from pprint import pprint
from sklearn.metrics import classification_report
%load_ext autoreload
%autoreload 2

project_dir = Path.cwd().parent
pd.set_option('max_colwidth', -1)
[code]

[/error]
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-6e2ffec00ab6> in <module>
13 from pytorch_pretrained_bert.optimization import *
14
---> 15 from finbert.finbert import *
16 import finbert.utils as tools
17 from pprint import pprint

ModuleNotFoundError: No module named 'finbert'
[error]

I tried to install finbert embedding it installed, but no luck. I even tried to install a finbert module.

I have been googling all options, as outlined above, but one seem to work.

How do I fix this error? I created an environment with

conda env create -f environment.yml

I have not used this command much. I generally use a reqiirements.txt file.

I am not sure of the difference.

Any help appreciated. I am using a docker jupyter notebook tensorflow image, I thought was the easiest way.

My os in Windows 10 pro.

But it keeps throwing this error.

Any help appreciated.

Respectfully,

ErnestTBass
Reply
#2
I think that I see the issue. I am just not sure what to do to fix it.

In the Github directory for this project there is a finbert directory and inside that directory
is fibert.py, plus other files most with the extension *.py.

That must be the module that they are talking about. How do I get it in the right location so the command
shown above that is giving the error goes away.

Any help appreciated. Thanks in advance.

Respectfully,

ErnstTBass
Reply
#3
Generally, you'll just put the directory (named finbert) with all the files inside somewhere in your python search path. As this program is expecting from finbert.finbert import *, to work, I would expect 2 levels of "finbert" directories before the *.py files.

Are you using Anaconda? Did you follow the anaconda installation directions?
Reply
#4
I am not using Anaconda, but I will try what you said. Thanks for your help.

Please understand, that although I use python everyday, there are still some basic errors that I occasionally trip over.

Thanks.


Respectfully,

ErnestTBass
Reply
#5
I have the following code to retrieve a sentiment from the given sentence using the FinBert model:

MAX_LEN = 160
class_names = ['negative', 'neutral', 'positive']

encoded_new = tokenizer.encode_plus(
review_text, # Sentence to encode.
add_special_tokens = True, # Add '[CLS]' and '[SEP]'
max_length = MAX_LEN, # Pad & truncate all sentences.
pad_to_max_length = True,
return_attention_mask = True, # Construct attn. masks.
return_tensors = 'pt', # Return pytorch tensors.
)

# Add the encoded sentence to the list.
input_idst = (encoded_new['input_ids'])
attention_maskst = (encoded_new['attention_mask'])

# Convert the lists into tensors.
input_idst = torch.cat([input_idst], dim=0)
attention_maskst = torch.cat([attention_maskst], dim=0)


new_test_output = model(input_idst, token_type_ids=None,
attention_mask=attention_maskst)

logits = new_test_output[0]
predicted = logits.detach().numpy()

# Store predictions
flat_predictions = np.concatenate(predicted, axis=0)

# For each sample, pick the label (0 or 1) with the higher score.
new_predictions = np.argmax(flat_predictions).flatten()

class_names[new_predictions[0]]



How can I apply this code to a whole column in a csv dataset (for each row) instead of an individual sentence and get predictions?
Sorry for the trivial question, since I am relatively new to Python. Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 717 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 22,953 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,173 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,316 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  pyside6 module not found ForeverNoob 4 1,275 Aug-18-2023, 04:36 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,393 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,229 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 964 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 8,222 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 934 May-15-2023, 02:38 PM
Last Post: tonynapoli2309

Forum Jump:

User Panel Messages

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