README / scripts /README.md.template
Fujitsu-LLM's picture
Add extra_gated_button_conten.
61d6422
---
extra_gated_prompt: {terms_of_use}
extra_gated_heading: Acknowledge License and Additional Terms of Use to accept the repository
extra_gated_button_content: Acknowledge License and Additional Terms of Use
license: apache-2.0
license_link: LICENSE
language:
- ja
- en
base_model:
- {base_model_id}
---
# {model_name}
本モデルは、国立研究開発法人 新エネルギー・産業技術総合開発機構(NEDO)の公募「[ポスト5G情報通信システム基盤強化研究開発事業/①ポスト5G情報通信システムの開発](https://www.nedo.go.jp/activities/ZZJP_100172.html)」および経済産業省が主催する「[Generative AI Accelerator Challenge(GENIAC)プロジェクト](https://www.meti.go.jp/policy/mono_info_service/geniac/index.html)」に採択された当富士通株式会社の提案事業[「論理推論を可能とする大規模言語モデルの研究開発」](https://pr.fujitsu.com/jp/news/2024/05/17.html)中に開発した、ナレッジグラフの生成/推論に特化した大規模言語モデル(LLM)の1つです。
同提案事業中に開発したモデルは、以下の表に一覧しています。
各モデルの評価結果や開発内容については、[富士通研究所の技術ブログ](https://blog.fltech.dev/entry/2024/10/15/Fujitsu-LLM-KG-ja)に詳細がありますので是非ご覧ください。
## Model Index
|モデル|名称|概要|
|---|---|---|
|[Fujitsu-LLM-KG-8x7B_cpt](https://huggingface.co/Fujitsu-LLM-KG/Fujitsu-LLM-KG-8x7B_cpt/)|共通事前学習済みLLM|ナレッジグラフ対訳コーパスで継続事前学習したLLM。|
|[Fujitsu-LLM-KG-8x7B_inst-infer_v1](https://huggingface.co/Fujitsu-LLM-KG/Fujitsu-LLM-KG-8x7B_inst-infer_v1/)|ナレッジグラフ推論LLM ver.1|日本語のマルチホップQAタスクデータで指示学習したLLM。|
|[Fujitsu-LLM-KG-8x7B_inst-infer_v2](https://huggingface.co/Fujitsu-LLM-KG/Fujitsu-LLM-KG-8x7B_inst-infer_v2/)|ナレッジグラフ推論LLM ver.2|英語のマルチホップQAタスクデータで指示学習したLLM。|
|[Fujitsu-LLM-KG-8x7B_inst-gen_ja](https://huggingface.co/Fujitsu-LLM-KG/Fujitsu-LLM-KG-8x7B_inst-gen_ja/)|ナレッジグラフ生成LLM(日本語版)|日本語の文書レベル関係抽出タスクデータで指示学習したLLM。|
|[Fujitsu-LLM-KG-8x7B_inst-gen_en](https://huggingface.co/Fujitsu-LLM-KG/Fujitsu-LLM-KG-8x7B_inst-gen_en/)|ナレッジグラフ生成LLM(英語版)|英語の文書レベル関係抽出タスクデータで指示学習したLLM。|
## Model Details
* **Developed by**: [Fujitsu-LLM](https://huggingface.co/Fujitsu-LLM/)
* **Base Model**: [{base_model_id}](https://huggingface.co/{base_model_id})
* **Language(s)**: Japanese, English
* **Library**: [NVIDIA/NeMo](https://github.com/NVIDIA/NeMo)
* **License**: [Apache-2.0](./LICENSE)
## Model Performance
* [富士通研究所の技術ブログ](https://blog.fltech.dev/entry/2024/10/15/Fujitsu-LLM-KG-ja)をご参照ください。
## How to use
### Preparation
必要なPythonモジュールをインストールする。
```sh
# Tested with the following versions; transformers==4.48.1, torch==2.5.1, and accelerate==1.3.0.
$ pip install transformers torch accelerate
```
ユーティリティを定義する。
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
class Fujitsu_LLM_KG:
"""The Fujitsu-LLM-KG-8x7B model.
"""
def __init__(self, model_id: str, *, device_map: str = "auto") -> None:
"""Initializes the model and tokenizer.
"""
self.model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map=device_map,
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
)
self.tokenizer = AutoTokenizer.from_pretrained(model_id, padding_side="left")
self.tokenizer.pad_token = self.tokenizer.eos_token
def generate(self, prompt:str,
*,
max_new_tokens: int = 2048,
num_beams: int = 1,
) -> str:
"""Generate an answer.
"""
tokenized = self.tokenizer(prompt, return_tensors="pt", padding=True)
with torch.no_grad():
outputs = self.model.generate(
tokenized["input_ids"].to("cuda"),
attention_mask=tokenized["attention_mask"].to("cuda"),
pad_token_id=self.tokenizer.eos_token_id,
max_new_tokens=max_new_tokens,
do_sample=False,
num_beams=num_beams,
)
answer = self.tokenizer.decode(outputs[0], skip_special_tokens=True)[len(prompt):]
return answer
def extract_turtle(text: str, *, with_rationale = False) -> str:
"""Extracts the RDF Turtle part from the output text of the Fujitsu-LLM-KG-8x7B models.
"""
TOKENS = ["<", "rel:", "rdf:", "]"]
if with_rationale:
TOKENS.append("#@")
turtle = ""
for line in text.splitlines():
line_ = line.strip()
if line == "" or any(line_.startswith(c) for c in TOKENS):
if turtle:
turtle += "\n"
turtle += line
return turtle
```
モデルを読み込む。
```python
kgllm = Fujitsu_LLM_KG("Fujitsu-LLM-KG/{model_name}")
```
{how_to_use}
## Training Datasets
{train_datasets}
## License
{model_name}の利用規約(Terms of Use)は、[LICENSE](./LICENSE)ファイルに記載しております。
## Risks and Limitations
{model_name}を利用した処理結果には、虚偽、偏り、他者の権利を侵害する内容、利用者が期待する効果や有用性を満たさない内容が含まれる可能性があります。
## Acknowledgements
本モデルの開発は、NEDOが推進する「ポスト5G情報通信システム基盤強化研究開発事業/ポスト5G情報通信システムの開発」の助成を受けたものです。
## Authors
* 富士通株式会社