-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-text2sql
- Loading branch information
Showing
43 changed files
with
202 additions
and
157 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
|
||
from unitxt import get_logger | ||
from unitxt.api import create_dataset, evaluate | ||
from unitxt.inference import ( | ||
CrossProviderInferenceEngine, | ||
) | ||
|
||
logger = get_logger() | ||
entity_types = ["Person", "Location", "Organization"] | ||
|
||
|
||
test_set = [ | ||
{ | ||
"text": "John lives in Texas.", | ||
"entity_types": entity_types, | ||
"spans_starts": [0, 14], | ||
"spans_ends": [5, 19], | ||
"labels": ["Person", "Location"], | ||
}, | ||
{ | ||
"text": "Phil works at Apple and eats an apple.", | ||
"entity_types": entity_types, | ||
"spans_starts": [0, 14], | ||
"spans_ends": [5, 19], | ||
"labels": ["Person", "Organization"], | ||
}, | ||
] | ||
|
||
|
||
dataset = create_dataset( | ||
task="tasks.ner.all_entity_types", | ||
test_set=test_set, | ||
split="test", | ||
format="formats.chat_api", | ||
) | ||
|
||
# Infer using Llama-3.2-1B base using HF API | ||
# model = HFPipelineBasedInferenceEngine( | ||
# model_name="Qwen/Qwen1.5-0.5B-Chat", max_new_tokens=32 | ||
# ) | ||
# Change to this to infer with external APIs: | ||
|
||
model = CrossProviderInferenceEngine(model="llama-3-8b-instruct", provider="watsonx") | ||
# The provider can be one of: ["watsonx", "together-ai", "open-ai", "aws", "ollama", "bam"] | ||
|
||
|
||
predictions = model(dataset) | ||
results = evaluate(predictions=predictions, data=dataset) | ||
|
||
print("Global Results:") | ||
print(results.global_scores.summary) | ||
|
||
print("Example prompt:") | ||
|
||
print(json.dumps(results.instance_scores[0]["source"], indent=4)) | ||
|
||
print("Instance Results:") | ||
print( | ||
results.instance_scores.to_df( | ||
columns=[ | ||
"text", | ||
"prediction", | ||
"processed_prediction", | ||
"processed_references", | ||
"score", | ||
"score_name", | ||
] | ||
).to_markdown() | ||
) |
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
Oops, something went wrong.