Update README.md
Browse files
README.md
CHANGED
|
@@ -7,4 +7,72 @@ license: apache-2.0
|
|
| 7 |
|
| 8 |
|
| 9 |
- 本文的训练流程主要包含:对Llama 2 进行藏文词表扩充,词表由32000 扩展至56724,提高模型在藏文的编解码效率。在TibetanGeneralCorpus 上使用Sentencepiece 工具训练基于Unigram 策略的藏文分词器。生成的词表与原版Llama 2 的32K 词表进行合并,排除重复的词
|
| 10 |
-
元后,得到扩充后词表规模为56724。用15G 的TibetanGeneralCorpus 和20G 的英、中混合文本进行CPT,采用自回归任务。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
- 本文的训练流程主要包含:对Llama 2 进行藏文词表扩充,词表由32000 扩展至56724,提高模型在藏文的编解码效率。在TibetanGeneralCorpus 上使用Sentencepiece 工具训练基于Unigram 策略的藏文分词器。生成的词表与原版Llama 2 的32K 词表进行合并,排除重复的词
|
| 10 |
+
元后,得到扩充后词表规模为56724。用15G 的TibetanGeneralCorpus 和20G 的英、中混合文本进行CPT,采用自回归任务。
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
加载模型并启动服务
|
| 15 |
+
``` python
|
| 16 |
+
# -*- coding: UTF-8 -*-
|
| 17 |
+
#
|
| 18 |
+
"""
|
| 19 |
+
功能为:主要用于调用llama2-7B对话模型
|
| 20 |
+
|
| 21 |
+
@File: llama2-7b-server.py
|
| 22 |
+
@Software: PyCharm
|
| 23 |
+
"""
|
| 24 |
+
import json
|
| 25 |
+
import logging
|
| 26 |
+
logging.basicConfig(
|
| 27 |
+
level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
from flask import Flask
|
| 31 |
+
from flask import Response
|
| 32 |
+
from flask import request
|
| 33 |
+
from flask_cors import CORS
|
| 34 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 35 |
+
|
| 36 |
+
app = Flask(__name__)
|
| 37 |
+
CORS(app)
|
| 38 |
+
app.logger.setLevel(logging.INFO)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def load_model(model_name):
|
| 43 |
+
# 加载模型和分词器
|
| 44 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 45 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 46 |
+
return tokenizer, model
|
| 47 |
+
|
| 48 |
+
def generate_response(model, tokenizer, text):
|
| 49 |
+
# 对输入的文本进行编码
|
| 50 |
+
inputs = tokenizer.encode(text, return_tensors='pt')
|
| 51 |
+
|
| 52 |
+
# 使用模型生成响应
|
| 53 |
+
output = model.generate(inputs, max_length=50, num_return_sequences=1)
|
| 54 |
+
|
| 55 |
+
# 对生成的输出进行解码,获取生成的文本
|
| 56 |
+
decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 57 |
+
return decoded_output
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@app.route('/api/chat', methods=['POST'])
|
| 62 |
+
def qtpdnn_v0():
|
| 63 |
+
"""Description"""
|
| 64 |
+
inputs = request.get_json()
|
| 65 |
+
response = generate_response(model, tokenizer, inputs.get("query"))
|
| 66 |
+
print("输出",response)
|
| 67 |
+
output=inputs
|
| 68 |
+
output.update({"output":response})
|
| 69 |
+
return Response(json.dumps(output, ensure_ascii=False), mimetype='application/json')
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
# 模型名称
|
| 74 |
+
model_name = 'merge_llama2_with_chinese_lora_13B/huggingface'
|
| 75 |
+
# 加载模型
|
| 76 |
+
tokenizer, model = load_model(model_name)
|
| 77 |
+
app.run(host='0.0.0.0', port=8718, debug=False, threaded=False, processes=1)
|
| 78 |
+
```
|