Downloads · 30 days
9
6% of all-time downloads
WariHima/hourai2-en-37m-gguf
hourai2-en-37m-gguf is a machine learning model from WariHima. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
llama2-baseモデルのような文章予測モデルです。 英語の入力予測用途に絞っているため、語彙をasciiコード範囲に絞っています。
Downloads · 30 days
9
6% of all-time downloads
All-time downloads
153
Public
Repo size
75.8 MB
Likes
0
Public
Click a slice to open those files.
.gguf75.8 MB · 100%
From the Hugging Face model README
llama2-baseモデルのような文章予測モデルです。
英語の入力予測用途に絞っているため、語彙をasciiコード範囲に絞っています。
from typing import Optional, List
import llama_cpp
from tokenizers import Tokenizer
class Hourai2enForGGUF(llama_cpp.Llama):
def load_tokenizer(self):
self.tokenizer = Tokenizer.from_file("./tokenizer.json")
def tokenize(
self, text: bytes, add_bos: bool = True, special: bool = False
) -> List[int]:
text = text.decode("utf-8")
return self.tokenizer.encode(text).ids #list[int]
def detokenize(
self,
tokens: List[int],
prev_tokens: Optional[List[int]] = None,
special: bool = False,
) -> bytes:
output= self.tokenizer.decode(tokens)
output = output.replace(" ", "[SPACE]")
output_list = output.split(" ")
output = "".join(output_list)
output = output.replace("[SPACE]", " ")
return output.encode("utf-8")
llm = Hourai2enForGGUF(
model_path="./hourai2-en-37m.gguf",
embedding=False,
verbose=False
)
llm.load_tokenizer()
while True:
input_text = input("入力した文章の続きが生成されます。exitを入力で終了:")
if input_text == "exit":
break
output_text = llm(
input_text,
max_tokens=10, # 生成する最大トークン数
temperature=0.5, # ランダム性(0.0に近づくほど確実な出力、1.0以上で多様化)
top_k=40, # 上位k個の候補に絞り込む
top_p=0.95, # 累積確率p以下の候補に絞り込む
repeat_penalty=1.1, # 同じ単語の繰り返しを抑制するペナルティ
stop=["\n"], # 途中で生成を止めるストップ文字列(リストで複数可)
echo=False
)["choices"][0]["text"]
print(f"入力|出力: {input_text}|{output_text}")