Model reference · open weights
sentence-luke-japanese-lite is an open-weight embedding model from sonoisa. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | sonoisa |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Parameters (lead) | 133M |
| Context | 514 tokens |
| Runs with | sentence-transformers |
| Released | 2023-03-19 |
| Popularity | 3k downloads / month |
| Licence | Open weights |
About
This is a Japanese sentence-LUKE model.
日本語用Sentence-LUKEモデルです。
日本語Sentence-BERTモデルと同一のデータセットと設定で学習しました。 手元の非公開データセットでは、日本語Sentence-BERTモデルと比べて定量的な精度が同等〜0.5pt程度高く、定性的な精度は本モデルの方が高い結果でした。
事前学習済みモデルとしてstudio-ousia/luke-japanese-base-liteを利用させていただきました。
推論の実行にはSentencePieceが必要です(pip install sentencepiece)。
from transformers import MLukeTokenizer, LukeModel
import torch
class SentenceLukeJapanese:
def __init__(self, model_name_or_path, device=None):
self.tokenizer = MLukeTokenizer.from_pretrained(model_name_or_path)
self.model = LukeModel.from_pretrained(model_name_or_path)
self.model.eval()
if device is None:
device = "cuda" if torch.cuda.is_available() else "cpu"
self.device = torch.device(device)
self.model.to(device)
def _mean_pooling(self, model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
@torch.no_grad()
def encode(self, sentences, batch_size=8):
all_embeddings = []
iterator = range(0, len(sentences), batch_size)
for batch_idx in iterator:
batch = sentences[batch_idx:batch_idx + batch_size]
encoded_input = self.tokenizer.batch_encode_plus(batch, padding="longest",
truncation=True, return_tensors="pt").to(self.device)
model_output = self.model(**encoded_input)
sentence_embeddings = self._mean_pooling(model_output, encoded_input["attention_mask"]).to('cpu')
all_embeddings.extend(sentence_embeddings)
return torch.stack(all_embeddings)
MODEL_NAME = "sonoisa/sentence-luke-japanese-base-lite"
model = SentenceLukeJapanese(MODEL_NAME)
sentences = ["暴走したAI", "暴走した人工知能"]
sentence_embeddings = model.encode(sentences, batch_size=8)
print("Sentence embeddings:", sentence_embeddings)
From the published model card. Full card on the HuggingFace links in the sidebar.
Using it via the API
Once AxForge deploys sentence-luke-japanese-lite for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (sentence-luke-japanese-lite below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/embeddings \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"sentence-luke-japanese-lite","input":"text to embed"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.