-
Notifications
You must be signed in to change notification settings - Fork 16
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
updated name info assets #149
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ed6df1
updated name info assets
firojalam 83e8c02
updated the script
firojalam 4803815
Updated the post-processing script, could not run it on the whole dat…
firojalam bfc4715
Updated the post-processing function, could not run it on the whole d…
firojalam a41e83e
Updated the post-processing function, could not run it on the whole d…
firojalam aaaed4f
Merge branch 'main' into update/demography/name_info
fdalvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
assets/benchmark_v1/demography/name_info/NameInfo_BLOOMZ_ZeroShot.py
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,168 @@ | ||
import os | ||
|
||
from arabic_llm_benchmark.datasets import NameInfoDataset | ||
from arabic_llm_benchmark.models import BLOOMPetalModel | ||
from arabic_llm_benchmark.tasks import DemographyNameInfoTask | ||
|
||
|
||
def config(): | ||
return { | ||
"dataset": NameInfoDataset, | ||
"dataset_args": {}, | ||
"task": DemographyNameInfoTask, | ||
"task_args": {}, | ||
"model": BLOOMPetalModel, | ||
"model_args": { | ||
"api_url": os.environ["API_URL"], | ||
"class_labels": [ | ||
"gb", | ||
"us", | ||
"cl", | ||
"fr", | ||
"ru", | ||
"pl", | ||
"in", | ||
"it", | ||
"kr", | ||
"gh", | ||
"ca", | ||
"sa", | ||
"at", | ||
"de", | ||
"cn", | ||
"br", | ||
"dk", | ||
"se", | ||
"bd", | ||
"cu", | ||
"jp", | ||
"be", | ||
"es", | ||
"co", | ||
"id", | ||
"iq", | ||
"pk", | ||
"tr", | ||
"il", | ||
"ch", | ||
"ar", | ||
"ro", | ||
"nl", | ||
"ps", | ||
"ug", | ||
"ir", | ||
"cg", | ||
"do", | ||
"ee", | ||
"tn", | ||
"gr", | ||
"np", | ||
"ie", | ||
"sy", | ||
"hu", | ||
"eg", | ||
"ma", | ||
"ve", | ||
"ph", | ||
"no", | ||
"bg", | ||
"si", | ||
"ke", | ||
"au", | ||
"et", | ||
"py", | ||
"af", | ||
"pt", | ||
"th", | ||
"bo", | ||
"mx", | ||
"lb", | ||
"za", | ||
"fi", | ||
"hr", | ||
"vn", | ||
"ly", | ||
"nz", | ||
"qa", | ||
"kh", | ||
"ci", | ||
"ng", | ||
"sg", | ||
"cm", | ||
"dz", | ||
"tz", | ||
"ae", | ||
"pe", | ||
"az", | ||
"lu", | ||
"ec", | ||
"cz", | ||
"ua", | ||
"uy", | ||
"sd", | ||
"ao", | ||
"my", | ||
"lv", | ||
"kw", | ||
"tw", | ||
"bh", | ||
"lk", | ||
"ye", | ||
"cr", | ||
"jo", | ||
"pa", | ||
"om", | ||
"uz", | ||
"by", | ||
"kz", | ||
], | ||
"max_tries": 10, | ||
}, | ||
"general_args": { | ||
"data_path": "data/demographic_attributes/name_info/wikidata_test.txt" | ||
}, | ||
} | ||
|
||
|
||
def prompt(input_sample): | ||
arr = input_sample.split() | ||
|
||
if len(arr) > 1000: | ||
input_sample = " ".join(arr[:1000]) | ||
else: | ||
input_sample = " ".join(arr) | ||
|
||
prompt_string = ( | ||
f"You are an expert annotator who can identify the country of a person based on name.\n" | ||
f"Label the country of the following person 'name'. Write ONLY the country code in ISO 3166-1 alpha-2 format.\n" | ||
f"Provide only label.\n\n" | ||
f"name: {input_sample}\n" | ||
f"country: \n" | ||
) | ||
|
||
return { | ||
"prompt": prompt_string, | ||
} | ||
|
||
|
||
def post_process(response): | ||
label = response["outputs"].strip() | ||
label = label.replace("<s>", "") | ||
label = label.replace("</s>", "") | ||
label = label.lower() | ||
|
||
label_list = config()["model_args"]["class_labels"] | ||
|
||
if "name: " in label: | ||
label_fixed = label.replace("name: ", "").lower() | ||
elif label.lower() in label_list: | ||
label_fixed = label.lower() | ||
elif ( | ||
"I'm sorry, but I cannot predict the country" in label | ||
or "I cannot predict the country" in label | ||
): | ||
label_fixed = None | ||
else: | ||
label_fixed = None | ||
|
||
return label_fixed |
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
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. Some cases like: {
"input": "جورج بوش الابن",
"label": "us",
"model_output": "country: US",
"filtered_output": null
} 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. The gpt4 fewshot asset also has similar outputs, but handles it, perhaps we just need to use the same postprocessing fn? |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Some cases that we can handle easily I think:
Also should we explicitly set to None if none of the labels are found? (e.g. when it outputs the original name back - sample 4 above)