Dongjin-kr commited on
Commit
01d6325
β€’
1 Parent(s): 1b6aaab
Files changed (1) hide show
  1. README.md +57 -1
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
- - Local
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