Views
No views yet
python -m pip install setfit1from setfit import SetFitModel
2import argilla as rg
3
4
5# Download from Hub and run inference
6model = SetFitModel.from_pretrained("mserras/setfit-alpaca-es-unprocessable-sample-detection")
7
8def instruct_fields_to_text(field_instruction: str, field_input: str, field_output: str):
9 """Given the instruction, input and output fields, return a text to be used by setfit"""
10 return f"INSTRUCTION:\n{field_instruction}\nINPUT:\n{field_input}\nOUTPUT:\n{field_output}\n"
11
12def sample_to_text(sample: rg.TextClassificationRecord) -> str:
13 """Converts and Argilla TextClassificationRecord to a text to be used by setfit"""
14 return instruct_fields_to_text(sample.inputs["1-instruction"], sample.inputs["2-input"], sample.inputs["3-output"])
15
16# For a given Argilla record:
17
18unprocessable_score = model.predict_proba([sample_to_text(argilla_record)])[0].tolist()[1]
19