-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
fix
] Use HfArgumentParser-compatible typing for prompts (#3178)
* Use HfArgumentParser-compatible typing for prompts * Add a simple test case * Use typing.Optional and Union for Python 3.9
- Loading branch information
Showing
2 changed files
with
38 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
|
||
from transformers import HfArgumentParser | ||
|
||
from sentence_transformers import SentenceTransformerTrainingArguments | ||
|
||
|
||
def test_hf_argument_parser(): | ||
# See https://github.com/UKPLab/sentence-transformers/issues/3090; | ||
# Ensure that the HfArgumentParser can be used to parse SentenceTransformerTrainingArguments. | ||
parser = HfArgumentParser(SentenceTransformerTrainingArguments) | ||
args = parser.parse_args( | ||
args=[ | ||
"--output_dir", | ||
"test_output_dir", | ||
"--prompts", | ||
'{"query_column": "query_prompt", "positive_column": "positive_prompt", "negative_column": "negative_prompt"}', | ||
] | ||
) | ||
assert args.output_dir == "test_output_dir" | ||
assert json.loads(args.prompts) == { | ||
"query_column": "query_prompt", | ||
"positive_column": "positive_prompt", | ||
"negative_column": "negative_prompt", | ||
} |