forked from yandex-cloud/yandex-ai-studio-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_few_shot.py
More file actions
executable file
·51 lines (39 loc) · 1.56 KB
/
run_few_shot.py
File metadata and controls
executable file
·51 lines (39 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# pylint: disable=duplicate-code
from __future__ import annotations
from yandex_cloud_ml_sdk import YCloudML
def main() -> None:
sdk = YCloudML(folder_id='yc.fomo.storage.prod.service')
sdk.setup_default_logging()
model = sdk.models.text_classifiers("yandexgpt").configure(
task_description="определи тип интента",
labels=[
"перевод",
"будильник",
"погода"
],
)
# result will be "погода": 1.0
result = model.run('переведи на английский "какая погода в лондоне?"')
for prediction in result:
print(prediction)
model = model.configure(
task_description="определи тип интента",
labels=[
"перевод",
"будильник",
"погода"
],
samples=[
{"text": "поставь будильник", "label": "будильник"},
{"text": "погода на завтра", "label": "погода"},
{"text": 'переведи фразу "поставь будильник"', "label": "перевод"},
]
)
# But with the given samples result will change to a "перевод": 0.99
result = model.run('переведи на английский "какая погода в лондоне?"')
for prediction in result:
print(prediction)
print(f'input_tokens= {result.input_tokens}')
if __name__ == '__main__':
main()