일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- query
- API
- docker
- licence delete curl
- aggregation
- aggs
- TensorFlow
- 차트
- License
- Kafka
- MySQL
- matplotlib
- Mac
- high level client
- zip 파일 암호화
- Python
- plugin
- Elasticsearch
- license delete
- Test
- flask
- token filter test
- ELASTIC
- analyzer test
- springboot
- Java
- 파이썬
- 900gle
- sort
- zip 암호화
Archives
- Today
- Total
개발잡부
[900gle] Text embedding API 본문
반응형
텍스트를 vector로 변환해주는 API
개발환경
- anaconda
- python 3.7
- tensorflow 2.x
- Request parameter
key | value |
keyword | String |
Respose
key | value |
vendors | 512차원 백터 |
# import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text
import kss, numpy
import json
from flask import Flask, request
from flask_restful import reqparse, abort, Api, Resource
app = Flask(__name__)
api = Api(app)
def getTextVectors(input):
vectors = module(input)
return [vector.numpy().tolist() for vector in vectors]
#
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, numpy.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
class Vector(Resource):
def post(self):
try:
parser = reqparse.RequestParser()
parser.add_argument('keyword', type=str)
args = parser.parse_args()
_keyword = args['keyword']
return {'vectors': json.dumps(getTextVectors(_keyword)[0], cls=NumpyEncoder)}
except Exception as e:
return {'error': str(e)}
api.add_resource(Vector, '/vectors')
if __name__ == '__main__':
module = hub.load("https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3")
app.run(debug=True)
Start
(base) ➜ ~ conda activate 900gle
cd project/900gle/python/tf-embeddings/api
python api/app.py
반응형
'900gle shopping > api' 카테고리의 다른 글
[900] Java High Level REST Client Query 3 (0) | 2022.01.27 |
---|---|
[900gle] Java High Level REST Client Query 2 (0) | 2022.01.26 |
[900gle] Search Template (0) | 2022.01.25 |
[900] Java High Level REST Client Query (0) | 2022.01.24 |
[900] Search API (0) | 2022.01.19 |
Comments