Python Forum
no module named finbert found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
no module named finbert found
#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


Messages In This Thread
no module named finbert found - by ErnestTBass - Nov-30-2020, 07:33 PM
RE: no module named finbert found - by ErnestTBass - Nov-30-2020, 08:05 PM
RE: no module named finbert found - by bowlofred - Nov-30-2020, 08:55 PM
RE: no module named finbert found - by ErnestTBass - Nov-30-2020, 09:18 PM
RE: no module named finbert found - by andrianas - Dec-05-2020, 06:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 873 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 23,723 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,554 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,437 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  pyside6 module not found ForeverNoob 4 1,415 Aug-18-2023, 04:36 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,504 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,329 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 1,032 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 9,031 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,006 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