-
Notifications
You must be signed in to change notification settings - Fork 0
returning model raw outputs as well #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,9 +129,10 @@ def prepare_model_inputs(self, texts: str, labels: str): | |
| return model_input, raw_batch | ||
|
|
||
| def predict_entities(self, text, labels, flat_ner=True, threshold=0.5, multi_label=False): | ||
| return self.batch_predict_entities( | ||
| all_entities, model_output = self.batch_predict_entities( | ||
| [text], labels, flat_ner=flat_ner, threshold=threshold, multi_label=multi_label | ||
| )[0] | ||
| ) | ||
| return all_entities[0] | ||
|
|
||
| @torch.no_grad() | ||
| def batch_predict_entities(self, texts, labels, flat_ner=True, threshold=0.5, multi_label=False): | ||
|
|
@@ -144,7 +145,8 @@ def batch_predict_entities(self, texts, labels, flat_ner=True, threshold=0.5, mu | |
|
|
||
| model_input, raw_batch = self.prepare_model_inputs(texts, labels) | ||
|
|
||
| model_output = self.model(**model_input)[0] | ||
| model_output_raw = self.model(**model_input) | ||
| model_output = model_output_raw[0] | ||
|
|
||
| if not isinstance(model_output, torch.Tensor): | ||
| model_output = torch.from_numpy(model_output) | ||
|
|
@@ -169,7 +171,7 @@ def batch_predict_entities(self, texts, labels, flat_ner=True, threshold=0.5, mu | |
| }) | ||
| all_entities.append(entities) | ||
|
|
||
| return all_entities | ||
| return all_entities, model_output_raw | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Changing Useful? React with 👍 / 👎. |
||
|
|
||
| def evaluate(self, test_data, flat_ner=False, multi_label=False, threshold=0.5, batch_size=12, entity_types=None): | ||
| """ | ||
|
|
@@ -427,4 +429,4 @@ def _from_pretrained( | |
| if (config.class_token_index==-1 or config.vocab_size == -1) and resize_token_embeddings: | ||
| gliner.data_processor.transformer_tokenizer.add_tokens(add_tokens) | ||
|
|
||
| return gliner | ||
| return gliner | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
model_outputvariable is assigned but never used. To signal that it's intentionally being ignored, you can use an underscore_as the variable name. This improves code clarity and adheres to common Python conventions for unused variables.