初始化项目,由ModelHub XC社区提供模型
Model: TinyModels/JujutsuKaiserver Source: Original Platform
This commit is contained in:
37
.gitattributes
vendored
Normal file
37
.gitattributes
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
jjk_index.faiss filter=lfs diff=lfs merge=lfs -text
|
||||
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||
184
README.md
Normal file
184
README.md
Normal file
@@ -0,0 +1,184 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
datasets:
|
||||
- TinyModels/jjk-wiki-corpus
|
||||
language:
|
||||
- en
|
||||
pipeline_tag: text-generation
|
||||
tags:
|
||||
- RAG
|
||||
- Qwen2.5
|
||||
- Jujutsu-Kaisen
|
||||
- Anime
|
||||
- Knowledge-Bot
|
||||
- Retrieval-Augmented-Generation
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
||||
# 🟣 JujutsuKaiserver
|
||||
|
||||
### *The Cursed Intelligence. The Canon Oracle.*
|
||||
|
||||
[](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct)
|
||||
[](https://huggingface.co/TinyModels/JujutsuKaiserver)
|
||||
[](https://huggingface.co/TinyModels/JujutsuKaiserver)
|
||||
[](LICENSE)
|
||||
[](https://huggingface.co/datasets/TinyModels/jjk-wiki-corpus)
|
||||
|
||||
<br/>
|
||||
|
||||
> *"Throughout Heaven and Earth, I alone am the honored one."*
|
||||
> — **Satoru Gojo** | and also this model, kind of.
|
||||
|
||||
<br/>
|
||||
|
||||
**JujutsuKaiserver** is a Retrieval-Augmented Generation (RAG) model built for one purpose:
|
||||
to answer anything and everything about the **Jujutsu Kaisen** universe — with canon-backed accuracy, zero hallucination tolerance, and the confidence of Unlimited Void.
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
## ⚡ What It Does
|
||||
|
||||
Ask it anything. Techniques. Domains. Arcs. Hidden lore. Character relationships. Cursed Energy mechanics. It retrieves the most relevant passages from a **200+ page wiki corpus**, feeds them into a fine-tuned **Qwen2.5-1.5B-Instruct** backbone, and gives you a clean, grounded answer — not a guess.
|
||||
|
||||
| Ask This | Get This |
|
||||
|----------|----------|
|
||||
| *"What is Sukuna's Shrine?"* | Full technique breakdown with canon context |
|
||||
| *"How does Mahito's Idle Transfiguration work?"* | Soul-level mechanics explained accurately |
|
||||
| *"What happened in the Shibuya Incident?"* | Arc summary backed by wiki chunks |
|
||||
| *"Who is the strongest Grade 1 sorcerer?"* | Ranked answer with sourced reasoning |
|
||||
|
||||
---
|
||||
|
||||
## 🧠 Architecture
|
||||
|
||||
```
|
||||
User Query
|
||||
│
|
||||
▼
|
||||
sentence-transformers (all-MiniLM-L6-v2)
|
||||
│ [embed query]
|
||||
▼
|
||||
FAISS Index (jjk_index.faiss)
|
||||
│ [top-5 relevant wiki chunks]
|
||||
▼
|
||||
Qwen2.5-1.5B-Instruct (4-bit)
|
||||
│ [context + question → chat template]
|
||||
▼
|
||||
Canon-grounded Answer
|
||||
```
|
||||
|
||||
### Model Composition
|
||||
|
||||
| Component | Details |
|
||||
|-----------|---------|
|
||||
| 🤖 **Base LLM** | `Qwen/Qwen2.5-1.5B-Instruct` (4-bit quantized) |
|
||||
| 🔢 **Embeddings** | `sentence-transformers/all-MiniLM-L6-v2` |
|
||||
| 📦 **Vector Store** | FAISS — `jjk_index.faiss` |
|
||||
| 📖 **Knowledge Base** | 120+ cleaned JJK Fandom Wiki articles (`chunks.txt`) |
|
||||
| 🔧 **Pipeline** | Custom `JujutsuKaiserver` class with Qwen chat template |
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
```python
|
||||
from huggingface_hub import snapshot_download
|
||||
|
||||
model_dir = snapshot_download("TinyModels/JujutsuKaiserver")
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, model_dir)
|
||||
from pipeline import JujutsuKaiserver
|
||||
|
||||
bot = JujutsuKaiserver(model_dir=model_dir)
|
||||
|
||||
# Ask anything
|
||||
print(bot.ask("What is Gojo's Domain Expansion called?"))
|
||||
# → "Infinite Void (無量空処). It..."
|
||||
```
|
||||
|
||||
> ⚠️ **Requirements**: `bitsandbytes`, GPU with **≥6 GB VRAM**. CPU inference works but is slow.
|
||||
|
||||
### Install Dependencies
|
||||
|
||||
```bash
|
||||
pip install transformers bitsandbytes faiss-cpu sentence-transformers huggingface_hub
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🖥️ Gradio Demo (Optional)
|
||||
|
||||
Spin up a local chat UI in seconds:
|
||||
|
||||
```python
|
||||
import gradio as gr
|
||||
from pipeline import JujutsuKaiserver
|
||||
|
||||
bot = JujutsuKaiserver(model_dir="<path_to_downloaded_model>")
|
||||
|
||||
def chat(message, history):
|
||||
return bot.ask(message)
|
||||
|
||||
gr.ChatInterface(
|
||||
fn=chat,
|
||||
title="🟣 JujutsuKaiserver",
|
||||
description="Ask anything about the JJK universe."
|
||||
).launch()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- 🔍 **Factual Q&A** — Every answer is grounded in retrieved wiki content, not imagination
|
||||
- 🚫 **Hallucination Guard** — Model is prompted to say *"I don't know"* when context is insufficient
|
||||
- 📚 **Deep Coverage** — 200+ wiki pages: characters, techniques, domains, arcs, lore
|
||||
- ⚡ **T4-Friendly** — 4-bit quantization means it runs on free Colab tiers
|
||||
- 🤖 **Gradio Ready** — One-script local demo included out of the box
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Known Limitations
|
||||
|
||||
- **Recent chapters** beyond the scraping date may not be indexed yet
|
||||
- **Ambiguous context** can still occasionally produce imperfect answers — being addressed via a feedback loop
|
||||
- **Roleplay mode** is possible with a custom system prompt, but this version is optimized for factual retrieval
|
||||
|
||||
---
|
||||
|
||||
## 🔮 Roadmap
|
||||
|
||||
- [ ] **Live Feedback Flagging** — 👍/👎 votes from the Gradio Space feed a correction dataset automatically
|
||||
- [ ] **Self-Correcting Pipeline** — Weekly DPO fine-tuning on flagged examples + FAISS index refresh
|
||||
- [ ] **Expanded KB** — Episode transcripts, manga panels text, community lore
|
||||
- [ ] **Streaming Support** — Token-by-token output for snappier UX
|
||||
|
||||
---
|
||||
|
||||
## 📂 Repo Structure
|
||||
|
||||
```
|
||||
JujutsuKaiserver/
|
||||
├── pipeline.py # Core RAG pipeline class
|
||||
├── jjk_index.faiss # FAISS vector index
|
||||
├── chunks.txt # Raw wiki knowledge base
|
||||
├── generation_config.json
|
||||
└── README.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
||||
**Built with 🩸 and cursed energy for the JJK community.**
|
||||
|
||||
*Got a question the bot fumbled? Open a [Discussion](https://huggingface.co/TinyModels/JujutsuKaiserver/discussions) and help us fix it.*
|
||||
|
||||
`TinyModels` • `QuantaSparkLabs` • Apache 2.0
|
||||
|
||||
</div>
|
||||
54
chat_template.jinja
Normal file
54
chat_template.jinja
Normal file
@@ -0,0 +1,54 @@
|
||||
{%- if tools %}
|
||||
{{- '<|im_start|>system\n' }}
|
||||
{%- if messages[0]['role'] == 'system' %}
|
||||
{{- messages[0]['content'] }}
|
||||
{%- else %}
|
||||
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
|
||||
{%- endif %}
|
||||
{{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
||||
{%- for tool in tools %}
|
||||
{{- "\n" }}
|
||||
{{- tool | tojson }}
|
||||
{%- endfor %}
|
||||
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
||||
{%- else %}
|
||||
{%- if messages[0]['role'] == 'system' %}
|
||||
{{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
|
||||
{%- else %}
|
||||
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- for message in messages %}
|
||||
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
|
||||
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
||||
{%- elif message.role == "assistant" %}
|
||||
{{- '<|im_start|>' + message.role }}
|
||||
{%- if message.content %}
|
||||
{{- '\n' + message.content }}
|
||||
{%- endif %}
|
||||
{%- for tool_call in message.tool_calls %}
|
||||
{%- if tool_call.function is defined %}
|
||||
{%- set tool_call = tool_call.function %}
|
||||
{%- endif %}
|
||||
{{- '\n<tool_call>\n{"name": "' }}
|
||||
{{- tool_call.name }}
|
||||
{{- '", "arguments": ' }}
|
||||
{{- tool_call.arguments | tojson }}
|
||||
{{- '}\n</tool_call>' }}
|
||||
{%- endfor %}
|
||||
{{- '<|im_end|>\n' }}
|
||||
{%- elif message.role == "tool" %}
|
||||
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
|
||||
{{- '<|im_start|>user' }}
|
||||
{%- endif %}
|
||||
{{- '\n<tool_response>\n' }}
|
||||
{{- message.content }}
|
||||
{{- '\n</tool_response>' }}
|
||||
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
||||
{{- '<|im_end|>\n' }}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- if add_generation_prompt %}
|
||||
{{- '<|im_start|>assistant\n' }}
|
||||
{%- endif %}
|
||||
111276
chunks.txt
Normal file
111276
chunks.txt
Normal file
File diff suppressed because it is too large
Load Diff
76
config.json
Normal file
76
config.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"architectures": [
|
||||
"Qwen2ForCausalLM"
|
||||
],
|
||||
"attention_dropout": 0.0,
|
||||
"bos_token_id": 151643,
|
||||
"dtype": "bfloat16",
|
||||
"eos_token_id": 151645,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 1536,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 8960,
|
||||
"layer_types": [
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention"
|
||||
],
|
||||
"max_position_embeddings": 32768,
|
||||
"max_window_layers": 21,
|
||||
"model_type": "qwen2",
|
||||
"num_attention_heads": 12,
|
||||
"num_hidden_layers": 28,
|
||||
"num_key_value_heads": 2,
|
||||
"pad_token_id": null,
|
||||
"quantization_config": {
|
||||
"_load_in_4bit": true,
|
||||
"_load_in_8bit": false,
|
||||
"bnb_4bit_compute_dtype": "float16",
|
||||
"bnb_4bit_quant_storage": "uint8",
|
||||
"bnb_4bit_quant_type": "nf4",
|
||||
"bnb_4bit_use_double_quant": true,
|
||||
"llm_int8_enable_fp32_cpu_offload": false,
|
||||
"llm_int8_has_fp16_weight": false,
|
||||
"llm_int8_skip_modules": null,
|
||||
"llm_int8_threshold": 6.0,
|
||||
"load_in_4bit": true,
|
||||
"load_in_8bit": false,
|
||||
"quant_method": "bitsandbytes"
|
||||
},
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_parameters": {
|
||||
"rope_theta": 1000000.0,
|
||||
"rope_type": "default"
|
||||
},
|
||||
"sliding_window": null,
|
||||
"tie_word_embeddings": true,
|
||||
"transformers_version": "5.0.0",
|
||||
"use_cache": true,
|
||||
"use_sliding_window": false,
|
||||
"vocab_size": 151936
|
||||
}
|
||||
147
cross_encoder_model/README.md
Normal file
147
cross_encoder_model/README.md
Normal file
@@ -0,0 +1,147 @@
|
||||
---
|
||||
tags:
|
||||
- sentence-transformers
|
||||
- cross-encoder
|
||||
- reranker
|
||||
base_model: cross-encoder/ms-marco-MiniLM-L6-v2
|
||||
pipeline_tag: text-ranking
|
||||
library_name: sentence-transformers
|
||||
---
|
||||
|
||||
# CrossEncoder based on cross-encoder/ms-marco-MiniLM-L6-v2
|
||||
|
||||
This is a [Cross Encoder](https://www.sbert.net/docs/cross_encoder/usage/usage.html) model finetuned from [cross-encoder/ms-marco-MiniLM-L6-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L6-v2) using the [sentence-transformers](https://www.SBERT.net) library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
|
||||
|
||||
## Model Details
|
||||
|
||||
### Model Description
|
||||
- **Model Type:** Cross Encoder
|
||||
- **Base model:** [cross-encoder/ms-marco-MiniLM-L6-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L6-v2) <!-- at revision c5ee24cb16019beea0893ab7796b1df96625c6b8 -->
|
||||
- **Maximum Sequence Length:** 512 tokens
|
||||
- **Number of Output Labels:** 1 label
|
||||
- **Supported Modality:** Text
|
||||
<!-- - **Training Dataset:** Unknown -->
|
||||
<!-- - **Language:** Unknown -->
|
||||
<!-- - **License:** Unknown -->
|
||||
|
||||
### Model Sources
|
||||
|
||||
- **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
|
||||
- **Documentation:** [Cross Encoder Documentation](https://www.sbert.net/docs/cross_encoder/usage/usage.html)
|
||||
- **Repository:** [Sentence Transformers on GitHub](https://github.com/huggingface/sentence-transformers)
|
||||
- **Hugging Face:** [Cross Encoders on Hugging Face](https://huggingface.co/models?library=sentence-transformers&other=cross-encoder)
|
||||
|
||||
### Full Model Architecture
|
||||
|
||||
```
|
||||
CrossEncoder(
|
||||
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'BertForSequenceClassification'})
|
||||
)
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Direct Usage (Sentence Transformers)
|
||||
|
||||
First install the Sentence Transformers library:
|
||||
|
||||
```bash
|
||||
pip install -U sentence-transformers
|
||||
```
|
||||
|
||||
Then you can load this model and run inference.
|
||||
```python
|
||||
from sentence_transformers import CrossEncoder
|
||||
|
||||
# Download from the 🤗 Hub
|
||||
model = CrossEncoder("cross_encoder_model_id")
|
||||
# Get scores for pairs of inputs
|
||||
pairs = [
|
||||
['How many calories in an egg', 'There are on average between 55 and 80 calories in an egg depending on its size.'],
|
||||
['How many calories in an egg', 'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.'],
|
||||
['How many calories in an egg', 'Most of the calories in an egg come from the yellow yolk in the center.'],
|
||||
]
|
||||
scores = model.predict(pairs)
|
||||
print(scores)
|
||||
# [ 9.9541 -2.0108 0.9186]
|
||||
|
||||
# Or rank different texts based on similarity to a single text
|
||||
ranks = model.rank(
|
||||
'How many calories in an egg',
|
||||
[
|
||||
'There are on average between 55 and 80 calories in an egg depending on its size.',
|
||||
'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.',
|
||||
'Most of the calories in an egg come from the yellow yolk in the center.',
|
||||
]
|
||||
)
|
||||
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
|
||||
```
|
||||
|
||||
<!--
|
||||
### Direct Usage (Transformers)
|
||||
|
||||
<details><summary>Click to see the direct usage in Transformers</summary>
|
||||
|
||||
</details>
|
||||
-->
|
||||
|
||||
<!--
|
||||
### Downstream Usage (Sentence Transformers)
|
||||
|
||||
You can finetune this model on your own dataset.
|
||||
|
||||
<details><summary>Click to expand</summary>
|
||||
|
||||
</details>
|
||||
-->
|
||||
|
||||
<!--
|
||||
### Out-of-Scope Use
|
||||
|
||||
*List how the model may foreseeably be misused and address what users ought not to do with the model.*
|
||||
-->
|
||||
|
||||
<!--
|
||||
## Bias, Risks and Limitations
|
||||
|
||||
*What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
|
||||
-->
|
||||
|
||||
<!--
|
||||
### Recommendations
|
||||
|
||||
*What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
|
||||
-->
|
||||
|
||||
## Training Details
|
||||
|
||||
### Framework Versions
|
||||
- Python: 3.12.13
|
||||
- Sentence Transformers: 5.4.1
|
||||
- Transformers: 5.0.0
|
||||
- PyTorch: 2.10.0+cu128
|
||||
- Accelerate: 1.13.0
|
||||
- Datasets: 4.0.0
|
||||
- Tokenizers: 0.22.2
|
||||
|
||||
## Citation
|
||||
|
||||
### BibTeX
|
||||
|
||||
<!--
|
||||
## Glossary
|
||||
|
||||
*Clearly define terms in order to be accessible across audiences.*
|
||||
-->
|
||||
|
||||
<!--
|
||||
## Model Card Authors
|
||||
|
||||
*Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
|
||||
-->
|
||||
|
||||
<!--
|
||||
## Model Card Contact
|
||||
|
||||
*Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
|
||||
-->
|
||||
36
cross_encoder_model/config.json
Normal file
36
cross_encoder_model/config.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"add_cross_attention": false,
|
||||
"architectures": [
|
||||
"BertForSequenceClassification"
|
||||
],
|
||||
"attention_probs_dropout_prob": 0.1,
|
||||
"bos_token_id": null,
|
||||
"classifier_dropout": null,
|
||||
"dtype": "float32",
|
||||
"eos_token_id": null,
|
||||
"gradient_checkpointing": false,
|
||||
"hidden_act": "gelu",
|
||||
"hidden_dropout_prob": 0.1,
|
||||
"hidden_size": 384,
|
||||
"id2label": {
|
||||
"0": "LABEL_0"
|
||||
},
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 1536,
|
||||
"is_decoder": false,
|
||||
"label2id": {
|
||||
"LABEL_0": 0
|
||||
},
|
||||
"layer_norm_eps": 1e-12,
|
||||
"max_position_embeddings": 512,
|
||||
"model_type": "bert",
|
||||
"num_attention_heads": 12,
|
||||
"num_hidden_layers": 6,
|
||||
"pad_token_id": 0,
|
||||
"position_embedding_type": "absolute",
|
||||
"tie_word_embeddings": true,
|
||||
"transformers_version": "5.0.0",
|
||||
"type_vocab_size": 2,
|
||||
"use_cache": true,
|
||||
"vocab_size": 30522
|
||||
}
|
||||
11
cross_encoder_model/config_sentence_transformers.json
Normal file
11
cross_encoder_model/config_sentence_transformers.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"__version__": {
|
||||
"pytorch": "2.10.0+cu128",
|
||||
"sentence_transformers": "5.4.1",
|
||||
"transformers": "5.0.0"
|
||||
},
|
||||
"activation_fn": "torch.nn.modules.linear.Identity",
|
||||
"default_prompt_name": null,
|
||||
"model_type": "CrossEncoder",
|
||||
"prompts": {}
|
||||
}
|
||||
3
cross_encoder_model/model.safetensors
Normal file
3
cross_encoder_model/model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5d5a1f2650eeb40eea5f06ddf0802b0ace0f102a28bddaa3a2cfbe65d54459ba
|
||||
size 90866404
|
||||
8
cross_encoder_model/modules.json
Normal file
8
cross_encoder_model/modules.json
Normal file
@@ -0,0 +1,8 @@
|
||||
[
|
||||
{
|
||||
"idx": 0,
|
||||
"name": "0",
|
||||
"path": "",
|
||||
"type": "sentence_transformers.base.modules.transformer.Transformer"
|
||||
}
|
||||
]
|
||||
10
cross_encoder_model/sentence_bert_config.json
Normal file
10
cross_encoder_model/sentence_bert_config.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"transformer_task": "sequence-classification",
|
||||
"modality_config": {
|
||||
"text": {
|
||||
"method": "forward",
|
||||
"method_output_name": "logits"
|
||||
}
|
||||
},
|
||||
"module_output_name": "scores"
|
||||
}
|
||||
3
cross_encoder_model/tokenizer.json
Normal file
3
cross_encoder_model/tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:91f1def9b9391fdabe028cd3f3fcc4efd34e5d1f08c3bf2de513ebb5911a1854
|
||||
size 711649
|
||||
18
cross_encoder_model/tokenizer_config.json
Normal file
18
cross_encoder_model/tokenizer_config.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"backend": "tokenizers",
|
||||
"clean_up_tokenization_spaces": true,
|
||||
"cls_token": "[CLS]",
|
||||
"do_basic_tokenize": true,
|
||||
"do_lower_case": true,
|
||||
"is_local": false,
|
||||
"mask_token": "[MASK]",
|
||||
"model_max_length": 512,
|
||||
"model_specific_special_tokens": {},
|
||||
"never_split": null,
|
||||
"pad_token": "[PAD]",
|
||||
"sep_token": "[SEP]",
|
||||
"strip_accents": null,
|
||||
"tokenize_chinese_chars": true,
|
||||
"tokenizer_class": "BertTokenizer",
|
||||
"unk_token": "[UNK]"
|
||||
}
|
||||
14
generation_config.json
Normal file
14
generation_config.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"bos_token_id": 151643,
|
||||
"do_sample": true,
|
||||
"eos_token_id": [
|
||||
151645,
|
||||
151643
|
||||
],
|
||||
"pad_token_id": 151643,
|
||||
"repetition_penalty": 1.1,
|
||||
"temperature": 0.7,
|
||||
"top_k": 20,
|
||||
"top_p": 0.8,
|
||||
"transformers_version": "5.0.0"
|
||||
}
|
||||
3
jjk_index.faiss
Normal file
3
jjk_index.faiss
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d7d183aeb61b0b4dc79f690bec5c362c85462bb95df622e5af223af17a85a722
|
||||
size 23717421
|
||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:06106640d26d6ec9358cae294790944e50e5d46a5eff37929a098d694286aad7
|
||||
size 1143327692
|
||||
45
pipeline.py
Normal file
45
pipeline.py
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
import json, torch, numpy as np
|
||||
from sentence_transformers import SentenceTransformer, CrossEncoder
|
||||
import faiss
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
|
||||
class JujutsuKaiserver:
|
||||
def __init__(self, model_dir="."):
|
||||
with open(f"{model_dir}/rag_config.json") as f:
|
||||
config = json.load(f)
|
||||
self.embedder = SentenceTransformer(config["embedder_model"])
|
||||
self.index = faiss.read_index(f"{model_dir}/jjk_index.faiss")
|
||||
with open(f"{model_dir}/chunks.txt", "r", encoding="utf-8") as f:
|
||||
raw = f.read().split("<|CHUNK_END|>")
|
||||
self.chunks = [c.strip() for c in raw if c.strip()]
|
||||
self.reranker = CrossEncoder(f"{model_dir}/cross_encoder_model")
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
|
||||
self.model = AutoModelForCausalLM.from_pretrained(
|
||||
model_dir,
|
||||
torch_dtype=torch.float16,
|
||||
device_map='auto',
|
||||
trust_remote_code=True
|
||||
)
|
||||
|
||||
def ask(self, question, max_tokens=300):
|
||||
q_lower = question.strip().lower()
|
||||
if q_lower in ('hi', 'hello', 'hey', 'yo', 'sup', 'hi there'):
|
||||
return "Hey there! I'm JujutsuKaiserver, your all-knowing JJK assistant. Ask me anything!"
|
||||
q_emb = self.embedder.encode([question]).astype('float32')
|
||||
_, indices = self.index.search(q_emb, 30)
|
||||
candidates = [self.chunks[i] for i in indices[0]]
|
||||
pairs = [(question, c) for c in candidates]
|
||||
scores = self.reranker.predict(pairs)
|
||||
reranked = sorted(zip(scores, candidates), reverse=True)[:4]
|
||||
best = [c for _, c in reranked]
|
||||
context = "\n\n".join(best)
|
||||
messages = [
|
||||
{"role": "system", "content": "You are JujutsuKaiserver, an expert on Jujutsu Kaisen. Answer using ONLY the provided context. Be friendly and concise."},
|
||||
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
|
||||
]
|
||||
prompt = self.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
||||
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device)
|
||||
outputs = self.model.generate(**inputs, max_new_tokens=max_tokens, temperature=0.7, do_sample=True, pad_token_id=self.tokenizer.eos_token_id)
|
||||
answer = self.tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
||||
return answer.strip()
|
||||
1
rag_config.json
Normal file
1
rag_config.json
Normal file
@@ -0,0 +1 @@
|
||||
{"embedder_model": "all-MiniLM-L6-v2"}
|
||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
|
||||
size 11421892
|
||||
29
tokenizer_config.json
Normal file
29
tokenizer_config.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"add_prefix_space": false,
|
||||
"backend": "tokenizers",
|
||||
"bos_token": null,
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|im_end|>",
|
||||
"errors": "replace",
|
||||
"extra_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|object_ref_start|>",
|
||||
"<|object_ref_end|>",
|
||||
"<|box_start|>",
|
||||
"<|box_end|>",
|
||||
"<|quad_start|>",
|
||||
"<|quad_end|>",
|
||||
"<|vision_start|>",
|
||||
"<|vision_end|>",
|
||||
"<|vision_pad|>",
|
||||
"<|image_pad|>",
|
||||
"<|video_pad|>"
|
||||
],
|
||||
"is_local": false,
|
||||
"model_max_length": 131072,
|
||||
"pad_token": "<|endoftext|>",
|
||||
"split_special_tokens": false,
|
||||
"tokenizer_class": "Qwen2Tokenizer",
|
||||
"unk_token": null
|
||||
}
|
||||
Reference in New Issue
Block a user