AI4Finance-Foundation / FinGPT

FinGPT: Open-Source Financial Large Language Models! Revolutionize 🔥 We release the trained model on HuggingFace.
https://ai4finance.org
MIT License
13.48k stars 1.88k forks source link

Removed bug related to the `get_sentiment` function #75

Closed mmmarchetti closed 12 months ago

mmmarchetti commented 12 months ago

In the original code, there is a bug related to the get_sentiment function. Here's an explanation of the bug:

In the get_sentiment function for the "local" data source, the code attempts to retrieve sentiment information for a given sentence from the self.sentiment_dict dictionary. However, if the sentence is not found in the dictionary, the code does not handle this situation gracefully.

In this part of the code:

response = self.sentiment_dict[sentence]

If sentence is not a key in self.sentiment_dict, a KeyError will be raised, causing the program to crash. This means that if there are any sentences in your input data that are not present in the sentiment dictionary, the code will break.

To address this issue, use the .get() method to do this, like so:

response = self.sentiment_dict.get(sentence, "")

This modification ensures that if sentence is not in the dictionary, it will return an empty string instead of raising a KeyError. This way, the code will handle cases where sentiment information is missing for a particular sentence.