-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from bolna-ai/feat/fillers
Feat/fillers
- Loading branch information
Showing
12 changed files
with
165 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from bolna.helpers.logger_config import configure_logger | ||
|
||
logger = configure_logger(__name__) | ||
|
||
|
||
class BaseClassifier: | ||
def __init__(self, model, prompt, labels, threshold = 0.6, multi_label = False): | ||
self.model_name = model | ||
self.prompt = prompt | ||
self.classification_labels = labels | ||
self.multi_label = multi_label | ||
self.threshold = threshold | ||
|
||
async def classify(self, messages): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
|
||
from dotenv import load_dotenv | ||
from transformers import AutoTokenizer, pipeline | ||
from optimum.onnxruntime import ORTModelForSequenceClassification | ||
|
||
from bolna.classification.classification import BaseClassifier | ||
from bolna.helpers.logger_config import configure_logger | ||
|
||
|
||
logger = configure_logger(__name__) | ||
|
||
|
||
load_dotenv() | ||
|
||
|
||
class DeBERTaClassifier(BaseClassifier): | ||
def __init__(self, model_id, prompt, labels, threshold, multi_label=False, filename = None): | ||
super().__init__(model_id, prompt, labels, multi_label, threshold) | ||
self.model_args = { "model_id": self.model_name} | ||
logger.info(f"Creating for {self.model_name}, classifier {model_id}") | ||
if filename is not None: | ||
self.model_args['file_name'] = filename | ||
self.model = ORTModelForSequenceClassification.from_pretrained(**self.model_args) | ||
self.tokenizer = AutoTokenizer.from_pretrained(model_id) | ||
self.tokenizer.model_input_names = ['input_ids', 'attention_mask'] | ||
self.classifier = pipeline("zero-shot-classification", model=self.model, tokenizer=self.tokenizer) | ||
|
||
def classify(self, text): | ||
output = self.classifier(text, self.classification_labels, multi_label=self.multi_label) | ||
logger.info(f"Most eligible response {output['labels'][0]}") | ||
return output['labels'][0] if output['scores'][0] > self.threshold else None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters