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
  ModuleNotFoundError: No module named 'Seal' Anldra12 10 458 Oct-06-2021, 12:12 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'bluetooth' Error Rovelin 4 524 Aug-31-2021, 04:04 PM
Last Post: Rovelin
  No module named 'pysolar' - even tough pysolar is installed - What am I doing wrong? Jghurt 5 944 May-08-2021, 07:03 PM
Last Post: Jghurt
  ModuleNotFoundError: No module named 'graph' Anldra12 3 1,764 May-02-2021, 02:41 PM
Last Post: Anldra12
  ModuleNotFoundError: No module named 'fpdf' KatMac 4 2,135 Apr-19-2021, 01:23 PM
Last Post: KatMac
  KafkaUtils module not found on spark 3 pyspark aupres 2 1,693 Feb-17-2021, 09:40 AM
Last Post: Larz60+
  'urllib3' Module not found when import 'requests' spanz 5 2,783 Jan-06-2021, 05:57 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'com' aleksg 9 2,905 Dec-14-2020, 05:00 PM
Last Post: Larz60+
Video ModuleNotFoundError: No module named ‘…’ Frank911 1 1,674 Dec-11-2020, 03:59 PM
Last Post: michael1789
  ModuleNotFoundError: No module named 'fcntl' ErnestTBass 2 7,016 Dec-05-2020, 02:39 PM
Last Post: ErnestTBass

Forum Jump:

User Panel Messages

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