Python Forum
no module named finbert found - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: no module named finbert found (/thread-31260.html)



no module named finbert found - ErnestTBass - Nov-30-2020

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


RE: no module named finbert found - ErnestTBass - Nov-30-2020

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


RE: no module named finbert found - bowlofred - Nov-30-2020

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?


RE: no module named finbert found - ErnestTBass - Nov-30-2020

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


RE: no module named finbert found - andrianas - Dec-05-2020

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!