初始化项目,由ModelHub XC社区提供模型
Model: jarminraws/hotel-llm-search Source: Original Platform
This commit is contained in:
36
.gitattributes
vendored
Normal file
36
.gitattributes
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
*.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
|
||||||
|
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||||
23
README.md
Normal file
23
README.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
license: apache-2.0
|
||||||
|
base_model: Qwen/Qwen3-1.7B
|
||||||
|
tags: [hotel-search, entity-extraction, lora-merged, qwen3]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Hotel Entity Extractor (Qwen3-1.7B, LoRA merged)
|
||||||
|
|
||||||
|
Fine-tuned to extract structured hotel-search params from natural-language queries
|
||||||
|
and return strict JSON. Trained filters-free of codes: `filters` is emitted as
|
||||||
|
human-readable PHRASES (e.g. `"swimming pool, pet friendly"`); a downstream matcher
|
||||||
|
resolves phrases -> production codes.
|
||||||
|
|
||||||
|
- **Input**: a hotel-search query + `today` date (DDMMYYYY date math).
|
||||||
|
- **Output**: JSON with destination, locality, hotelName, checkin/checkoutDate,
|
||||||
|
adult/room/child/childAges/infantCount, sortCriteria, min/maxPrice, filters,
|
||||||
|
deepSearch, isNearMe, resetAction.
|
||||||
|
- **Prompt/schema contract**: bundled as `contract.py` in this repo. The serving
|
||||||
|
layer MUST use this exact prompt (it verifies byte-parity at startup).
|
||||||
|
|
||||||
|
Serve with vLLM (see the entity-extraction-serving repo). Raw model output is
|
||||||
|
exposed by the API; date validation + filter phrase->code resolution happen in
|
||||||
|
the calling service.
|
||||||
89
chat_template.jinja
Normal file
89
chat_template.jinja
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
{%- if tools %}
|
||||||
|
{{- '<|im_start|>system\n' }}
|
||||||
|
{%- if messages[0].role == 'system' %}
|
||||||
|
{{- messages[0].content + '\n\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- "# 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' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
||||||
|
{%- for message in messages[::-1] %}
|
||||||
|
{%- set index = (messages|length - 1) - loop.index0 %}
|
||||||
|
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
||||||
|
{%- set ns.multi_step_tool = false %}
|
||||||
|
{%- set ns.last_query_index = index %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- for message in messages %}
|
||||||
|
{%- if message.content is string %}
|
||||||
|
{%- set content = message.content %}
|
||||||
|
{%- else %}
|
||||||
|
{%- set content = '' %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
||||||
|
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
||||||
|
{%- elif message.role == "assistant" %}
|
||||||
|
{%- set reasoning_content = '' %}
|
||||||
|
{%- if message.reasoning_content is string %}
|
||||||
|
{%- set reasoning_content = message.reasoning_content %}
|
||||||
|
{%- else %}
|
||||||
|
{%- if '</think>' in content %}
|
||||||
|
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
||||||
|
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- if loop.index0 > ns.last_query_index %}
|
||||||
|
{%- if loop.last or (not loop.last and reasoning_content) %}
|
||||||
|
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
||||||
|
{%- else %}
|
||||||
|
{{- '<|im_start|>' + message.role + '\n' + content }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- else %}
|
||||||
|
{{- '<|im_start|>' + message.role + '\n' + content }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- if message.tool_calls %}
|
||||||
|
{%- for tool_call in message.tool_calls %}
|
||||||
|
{%- if (loop.first and content) or (not loop.first) %}
|
||||||
|
{{- '\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- if tool_call.function %}
|
||||||
|
{%- set tool_call = tool_call.function %}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '<tool_call>\n{"name": "' }}
|
||||||
|
{{- tool_call.name }}
|
||||||
|
{{- '", "arguments": ' }}
|
||||||
|
{%- if tool_call.arguments is string %}
|
||||||
|
{{- tool_call.arguments }}
|
||||||
|
{%- else %}
|
||||||
|
{{- tool_call.arguments | tojson }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '}\n</tool_call>' }}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '<|im_end|>\n' }}
|
||||||
|
{%- elif message.role == "tool" %}
|
||||||
|
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
||||||
|
{{- '<|im_start|>user' }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '\n<tool_response>\n' }}
|
||||||
|
{{- 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' }}
|
||||||
|
{%- if enable_thinking is defined and enable_thinking is false %}
|
||||||
|
{{- '<think>\n\n</think>\n\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
63
config.json
Normal file
63
config.json
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
{
|
||||||
|
"architectures": [
|
||||||
|
"Qwen3ForCausalLM"
|
||||||
|
],
|
||||||
|
"attention_bias": false,
|
||||||
|
"attention_dropout": 0.0,
|
||||||
|
"bos_token_id": 151643,
|
||||||
|
"dtype": "bfloat16",
|
||||||
|
"eos_token_id": 151645,
|
||||||
|
"head_dim": 128,
|
||||||
|
"hidden_act": "silu",
|
||||||
|
"hidden_size": 2048,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"intermediate_size": 6144,
|
||||||
|
"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": 40960,
|
||||||
|
"max_window_layers": 28,
|
||||||
|
"model_type": "qwen3",
|
||||||
|
"num_attention_heads": 16,
|
||||||
|
"num_hidden_layers": 28,
|
||||||
|
"num_key_value_heads": 8,
|
||||||
|
"pad_token_id": null,
|
||||||
|
"rms_norm_eps": 1e-06,
|
||||||
|
"rope_parameters": {
|
||||||
|
"rope_theta": 1000000,
|
||||||
|
"rope_type": "default"
|
||||||
|
},
|
||||||
|
"sliding_window": null,
|
||||||
|
"tie_word_embeddings": true,
|
||||||
|
"transformers_version": "5.8.1",
|
||||||
|
"use_cache": true,
|
||||||
|
"use_sliding_window": false,
|
||||||
|
"vocab_size": 151936
|
||||||
|
}
|
||||||
127
contract.py
Normal file
127
contract.py
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
"""SHARED CONTRACT — the prompt + output schema the model is trained and served on.
|
||||||
|
|
||||||
|
This file is the single source of truth for:
|
||||||
|
- FIELD_ORDER : canonical key order of the extracted JSON
|
||||||
|
- build_prompt() : the EXACT prompt string used at train AND inference time
|
||||||
|
- format_completion() : training target serialization (also used by eval)
|
||||||
|
- extract_json() : brace-matched JSON extraction from raw model text
|
||||||
|
- HotelExtraction : Pydantic schema for validation
|
||||||
|
- validate() : parse+validate -> clean dict (or None)
|
||||||
|
|
||||||
|
It is intentionally DEPENDENCY-LIGHT (only json + pydantic) so both the heavy
|
||||||
|
training env and the lean serving env can import it. A COPY of this file lives in
|
||||||
|
BOTH training/ and deployment/; tests/test_contract_parity.py asserts they are
|
||||||
|
byte-identical, so the prompt can never silently drift between train and serve.
|
||||||
|
|
||||||
|
DO NOT EDIT one copy without the other. Edit the source, re-sync, re-run the test.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
from typing import Any, Literal, Optional
|
||||||
|
|
||||||
|
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
||||||
|
|
||||||
|
DEFAULT_BASE_MODEL = "Qwen/Qwen3-1.7B"
|
||||||
|
|
||||||
|
# `filters` is emitted as a comma-separated string of NATURAL PHRASES
|
||||||
|
# (e.g. "swimming pool, pet friendly"), NOT production codes. A downstream matcher
|
||||||
|
# resolves phrases -> codes (FL_HF_29, ...), keeping the model taxonomy-agnostic.
|
||||||
|
FIELD_ORDER = [
|
||||||
|
"destination", "locality", "hotelName", "checkinDate", "checkoutDate",
|
||||||
|
"adultCount", "roomCount", "childCount", "childAges", "infantCount",
|
||||||
|
"sortCriteria", "minPrice", "maxPrice", "filters", "deepSearch", "isNearMe", "resetAction",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def build_prompt(query: str, today: str) -> str:
|
||||||
|
"""The exact user-message content used for BOTH training and inference."""
|
||||||
|
return (
|
||||||
|
"Extract hotel-search entities.\n"
|
||||||
|
"Return strict JSON only.\n"
|
||||||
|
"Schema:\n"
|
||||||
|
"destination, locality, hotelName, checkinDate, checkoutDate, "
|
||||||
|
"adultCount, roomCount, childCount, childAges, infantCount, "
|
||||||
|
"sortCriteria, minPrice, maxPrice, filters, deepSearch, isNearMe, resetAction.\n\n"
|
||||||
|
"Rules:\n"
|
||||||
|
"- Dates are DDMMYYYY.\n"
|
||||||
|
'- deepSearch and isNearMe must be "true" or "false".\n'
|
||||||
|
"- filters is a comma-separated list of amenity/type phrases (e.g. "
|
||||||
|
'"swimming pool, pet friendly"); prefix removals with "no ".\n'
|
||||||
|
"- Omit unknown optional fields.\n\n"
|
||||||
|
f"today={today}\n"
|
||||||
|
f"query={query}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def format_completion(expected: dict[str, Any]) -> str:
|
||||||
|
"""Stable-key-order minified JSON — the training target / gold serialization."""
|
||||||
|
ordered = {f: expected[f] for f in FIELD_ORDER if f in expected}
|
||||||
|
for k in expected:
|
||||||
|
if k not in ordered:
|
||||||
|
ordered[k] = expected[k]
|
||||||
|
return json.dumps(ordered, ensure_ascii=False, separators=(",", ":"))
|
||||||
|
|
||||||
|
|
||||||
|
def extract_json(text: str) -> dict | None:
|
||||||
|
"""Pull the first balanced {...} object out of raw model text."""
|
||||||
|
start = text.find("{")
|
||||||
|
if start < 0:
|
||||||
|
return None
|
||||||
|
depth = 0
|
||||||
|
in_str = esc = False
|
||||||
|
for i in range(start, len(text)):
|
||||||
|
c = text[i]
|
||||||
|
if esc:
|
||||||
|
esc = False
|
||||||
|
continue
|
||||||
|
if c == "\\":
|
||||||
|
esc = True
|
||||||
|
continue
|
||||||
|
if c == '"':
|
||||||
|
in_str = not in_str
|
||||||
|
continue
|
||||||
|
if in_str:
|
||||||
|
continue
|
||||||
|
if c == "{":
|
||||||
|
depth += 1
|
||||||
|
elif c == "}":
|
||||||
|
depth -= 1
|
||||||
|
if depth == 0:
|
||||||
|
try:
|
||||||
|
return json.loads(text[start:i + 1])
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class HotelExtraction(BaseModel):
|
||||||
|
"""Output contract. `filters` is a comma-separated PHRASE string (e.g.
|
||||||
|
"swimming pool, pet friendly"); a downstream matcher resolves it to codes."""
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
deepSearch: Literal["true", "false"]
|
||||||
|
isNearMe: Literal["true", "false"]
|
||||||
|
destination: Optional[str] = Field(default=None, min_length=1)
|
||||||
|
locality: Optional[str] = Field(default=None, min_length=1)
|
||||||
|
hotelName: Optional[str] = Field(default=None, min_length=1)
|
||||||
|
checkinDate: Optional[str] = Field(default=None, pattern=r"^\d{8}$")
|
||||||
|
checkoutDate: Optional[str] = Field(default=None, pattern=r"^\d{8}$")
|
||||||
|
adultCount: Optional[int] = Field(default=None, ge=0, le=20)
|
||||||
|
roomCount: Optional[int] = Field(default=None, ge=0, le=20)
|
||||||
|
childCount: Optional[int] = Field(default=None, ge=0, le=20)
|
||||||
|
childAges: Optional[list[int]] = None
|
||||||
|
infantCount: Optional[int] = Field(default=None, ge=0, le=20)
|
||||||
|
sortCriteria: Optional[Literal["SC_P_LH", "SC_P_HL", "SC_UR", "SC_P", "SC_DIST"]] = None
|
||||||
|
minPrice: Optional[int] = Field(default=None, ge=0, le=10_000_000)
|
||||||
|
maxPrice: Optional[int] = Field(default=None, ge=0, le=10_000_000)
|
||||||
|
filters: Optional[str] = Field(default=None, min_length=1)
|
||||||
|
resetAction: Optional[Literal["filters", "guests", "dates", "all"]] = None
|
||||||
|
|
||||||
|
|
||||||
|
def validate(d: dict) -> dict | None:
|
||||||
|
"""Validate a parsed dict against the schema; return clean dict or None."""
|
||||||
|
try:
|
||||||
|
return HotelExtraction.model_validate(d).model_dump(exclude_none=True)
|
||||||
|
except ValidationError:
|
||||||
|
return None
|
||||||
13
generation_config.json
Normal file
13
generation_config.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"bos_token_id": 151643,
|
||||||
|
"do_sample": true,
|
||||||
|
"eos_token_id": [
|
||||||
|
151645,
|
||||||
|
151643
|
||||||
|
],
|
||||||
|
"pad_token_id": 151643,
|
||||||
|
"temperature": 0.6,
|
||||||
|
"top_k": 20,
|
||||||
|
"top_p": 0.95,
|
||||||
|
"transformers_version": "5.8.1"
|
||||||
|
}
|
||||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:081680104296e847046cb301f532cbce1f0116105fa07050a0cf48f7f350a98c
|
||||||
|
size 3441185608
|
||||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
|
||||||
|
size 11422650
|
||||||
30
tokenizer_config.json
Normal file
30
tokenizer_config.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"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": true,
|
||||||
|
"local_files_only": 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