spacesedan commited on
Commit
f870834
·
1 Parent(s): bb9b235

feat: changing model again roBERTa -> longformer

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -7,10 +7,10 @@ from typing import List
7
  # Initialize FastAPI
8
  app = FastAPI()
9
 
10
- # Load RoBERTa sentiment analysis model
11
  sentiment_pipeline = pipeline(
12
  "sentiment-analysis",
13
- model="cardiffnlp/twitter-roberta-base-sentiment"
14
  )
15
 
16
  # Request models
@@ -28,7 +28,7 @@ class SentimentResponse(BaseModel):
28
  sentiment_label: str
29
  confidence: float
30
 
31
- # Mapping RoBERTa labels to a floating-point scale
32
  LABEL_MAP = {
33
  "LABEL_0": -1.0, # Negative
34
  "LABEL_1": 0.0, # Neutral
@@ -43,7 +43,7 @@ def analyze_sentiment(request: SentimentRequest):
43
  label = result["label"]
44
  score = result["score"]
45
 
46
- # Convert RoBERTa labels to floating-point scores
47
  sentiment_score = LABEL_MAP[label]
48
  confidence = round(score, 3)
49
 
@@ -65,7 +65,7 @@ def analyze_sentiment_batch(request: BatchSentimentRequest):
65
  label = result["label"]
66
  score = result["score"]
67
 
68
- # Convert RoBERTa labels to floating-point scores
69
  sentiment_score = LABEL_MAP[label]
70
  confidence = round(score, 3)
71
 
@@ -82,4 +82,4 @@ def analyze_sentiment_batch(request: BatchSentimentRequest):
82
  # Root endpoint
83
  @app.get("/")
84
  def root():
85
- return {"message": "RoBERTa Sentiment Analysis API is running!"}
 
7
  # Initialize FastAPI
8
  app = FastAPI()
9
 
10
+ # Load Longformer sentiment analysis model
11
  sentiment_pipeline = pipeline(
12
  "sentiment-analysis",
13
+ model="allenai/longformer-base-4096"
14
  )
15
 
16
  # Request models
 
28
  sentiment_label: str
29
  confidence: float
30
 
31
+ # Mapping Longformer labels to a floating-point scale
32
  LABEL_MAP = {
33
  "LABEL_0": -1.0, # Negative
34
  "LABEL_1": 0.0, # Neutral
 
43
  label = result["label"]
44
  score = result["score"]
45
 
46
+ # Convert Longformer labels to floating-point scores
47
  sentiment_score = LABEL_MAP[label]
48
  confidence = round(score, 3)
49
 
 
65
  label = result["label"]
66
  score = result["score"]
67
 
68
+ # Convert Longformer labels to floating-point scores
69
  sentiment_score = LABEL_MAP[label]
70
  confidence = round(score, 3)
71
 
 
82
  # Root endpoint
83
  @app.get("/")
84
  def root():
85
+ return {"message": "Longformer Sentiment Analysis API is running!"}