Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update endpoint to use new model files #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/seer/seer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def def_severity_endpoint():
try:
data = request.get_json()
severity = embeddings_model.severity_score(data.get("message", ""))
results = {"severity": str(severity[0][1])}
results = {"severity": str(severity)}
return results
except Exception as e:
app.logger.exception("Error processing request")
Expand Down
13 changes: 5 additions & 8 deletions src/seer/severity/severity_inference.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import sentry_sdk
import torch
from transformers import BertForSequenceClassification, BertTokenizerFast
from transformers import RobertaForSequenceClassification, RobertaTokenizerFast
from joblib import load


class SeverityInference:
def __init__(self, embeddings_path, tokenizer_path, classifier_path):
"""Initialize the inference class with pre-trained models and tokenizer."""
#TODO: needs to read from GCS
self.embeddings_model = BertForSequenceClassification.from_pretrained(
self.embeddings_model = RobertaForSequenceClassification.from_pretrained(
embeddings_path
)
#TODO: needs to read from GCS
self.tokenizer = BertTokenizerFast.from_pretrained(tokenizer_path)
self.tokenizer = RobertaTokenizerFast.from_pretrained(tokenizer_path)
self.device = (
torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
)
#TODO: needs to read from GCS
self.classifier = load(classifier_path)

def get_embeddings(self, text, max_len=128):
Expand Down Expand Up @@ -49,5 +46,5 @@ def severity_score(self, text):
with sentry_sdk.start_span(
op="model.severity", description="predict_proba"
):
pred = self.classifier.predict_proba(embeddings.reshape(1, -1))
return pred
pred = self.classifier.predict(embeddings.reshape(1, -1))[0]
return min(1.0, max(0.0, pred))
Loading