Fixed Sentiment crash (truncation) (#305)

Added truncation attribute.... and it works!
This commit is contained in:
Sebastian 2023-11-02 18:58:48 +01:00 committed by GitHub
parent f3f6c40a49
commit 0d1162efbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -19,7 +19,6 @@ class SentimentPipeline:
def __init__(self, conn_string: MongoConnection) -> None:
"""Method to connect to StagingDB."""
self.connect_string = conn_string
self.connect_string.database = "transparenzregister_ner"
self.connector = conn.MongoConnector(self.connect_string)
self.news_obj = news.MongoNewsService(self.connector)
@ -47,7 +46,6 @@ class SentimentPipeline:
)
sentiment_service_func = selected_service.sentiment_transformer
# sents = selected_service.sentiment_spacy(text)
sents = sentiment_service_func(text)
sentiment = {"label": sents[0], "score": sents[1]}
self.news_obj.collection.update_one(

View File

@ -69,7 +69,9 @@ class SentimentAnalysisService:
"""Method to initialize transformer."""
# loading the sentiment model(~ 436MB) for transformer
self.sentiment_analyzer = pipeline(
"sentiment-analysis", model="oliverguhr/german-sentiment-bert"
"sentiment-analysis",
model="oliverguhr/german-sentiment-bert",
truncation=True,
)
def sentiment_spacy(self, doc: str) -> tuple: