Dongjin-kr
commited on
Commit
β’
01d6325
1
Parent(s):
1b6aaab
update
Browse files
README.md
CHANGED
@@ -21,7 +21,7 @@ ko-rerankerλ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
21 |
|
22 |
## 1.Usage
|
23 |
|
24 |
-
-
|
25 |
```
|
26 |
def exp_normalize(x):
|
27 |
b = x.max()
|
@@ -44,6 +44,62 @@ ko-rerankerλ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
44 |
print (f'first: {scores[0]}, second: {scores[1]}')
|
45 |
```
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
## 2. Backgound
|
48 |
- #### <span style="#FF69B4;"> **컨νμ€νΈ μμκ° μ νλμ μν₯ μ€λ€**([Lost in Middel, *Liu et al., 2023*](https://arxiv.org/pdf/2307.03172.pdf)) </span>
|
49 |
|
|
|
21 |
|
22 |
## 1.Usage
|
23 |
|
24 |
+
- using Transformers
|
25 |
```
|
26 |
def exp_normalize(x):
|
27 |
b = x.max()
|
|
|
44 |
print (f'first: {scores[0]}, second: {scores[1]}')
|
45 |
```
|
46 |
|
47 |
+
- using SageMaker
|
48 |
+
```
|
49 |
+
import sagemaker
|
50 |
+
import boto3
|
51 |
+
from sagemaker.huggingface import HuggingFaceModel
|
52 |
+
|
53 |
+
try:
|
54 |
+
role = sagemaker.get_execution_role()
|
55 |
+
except ValueError:
|
56 |
+
iam = boto3.client('iam')
|
57 |
+
role = iam.get_role(RoleName='sagemaker_execution_role')['Role']['Arn']
|
58 |
+
|
59 |
+
# Hub Model configuration. https://huggingface.co/models
|
60 |
+
hub = {
|
61 |
+
'HF_MODEL_ID':'Dongjin-kr/ko-reranker',
|
62 |
+
'HF_TASK':'text-classification'
|
63 |
+
}
|
64 |
+
|
65 |
+
# create Hugging Face Model Class
|
66 |
+
huggingface_model = HuggingFaceModel(
|
67 |
+
transformers_version='4.28.1',
|
68 |
+
pytorch_version='2.0.0',
|
69 |
+
py_version='py310',
|
70 |
+
env=hub,
|
71 |
+
role=role,
|
72 |
+
)
|
73 |
+
|
74 |
+
# deploy model to SageMaker Inference
|
75 |
+
predictor = huggingface_model.deploy(
|
76 |
+
initial_instance_count=1, # number of instances
|
77 |
+
instance_type='ml.g5.large' # ec2 instance type
|
78 |
+
)
|
79 |
+
|
80 |
+
runtime_client = boto3.Session().client('sagemaker-runtime')
|
81 |
+
payload = json.dumps(
|
82 |
+
{
|
83 |
+
"inputs": [
|
84 |
+
{"text": "λλ λλ₯Ό μ«μ΄ν΄", "text_pair": "λλ λλ₯Ό μ¬λν΄"},
|
85 |
+
{"text": "λλ λλ₯Ό μ’μν΄", "text_pair": "λμ λν λμ κ°μ μ μ¬λ μΌ μλ μμ΄"}
|
86 |
+
]
|
87 |
+
}
|
88 |
+
)
|
89 |
+
|
90 |
+
response = runtime_client.invoke_endpoint(
|
91 |
+
EndpointName="<endpoint-name>",
|
92 |
+
ContentType="application/json",
|
93 |
+
Accept=application/json",
|
94 |
+
Body=payload
|
95 |
+
)
|
96 |
+
|
97 |
+
## deserialization
|
98 |
+
out = json.loads(response['Body'].read().decode()) ## for json
|
99 |
+
print (f'Response: {out}')
|
100 |
+
|
101 |
+
```
|
102 |
+
|
103 |
## 2. Backgound
|
104 |
- #### <span style="#FF69B4;"> **컨νμ€νΈ μμκ° μ νλμ μν₯ μ€λ€**([Lost in Middel, *Liu et al., 2023*](https://arxiv.org/pdf/2307.03172.pdf)) </span>
|
105 |
|