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

sst5 support instead of sst2 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/pipelines/sentiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use serde::{Deserialize, Serialize};
pub enum SentimentPolarity {
Positive,
Negative,
Neutral,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -141,8 +142,10 @@ impl SentimentModel {
let labels = self.sequence_classification_model.predict(input);
let mut sentiments = Vec::with_capacity(labels.len());
for label in labels {
let polarity = if label.id == 1 {
let polarity = if label.id == 4 || label.id == 3 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so this basically gains us sst5 but loses us sst2 but that's fine because the current production model we're using is sst5. And this is why, as you mention in the PR description, it'd be great to get this into rust-bert as something configurable per model so the sentiment pipeline works with whatever IDs the underlying model will return?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - and I think it would be a fun rust-bert contribution to try, but maybe tricky.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wonder how these models work and if we could get "lucky" with a "specify the neutral range and anything above that is positive and anything below is negative". But it's technically more flexible to require the mapping as you say. Yeah interesting to try and figure out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the models often come with something like config.json which explicitly contains the mapping.

SentimentPolarity::Positive
} else if label.id == 2 {
SentimentPolarity::Neutral
} else {
SentimentPolarity::Negative
};
Expand Down