QAway-to commited on
Commit
1c31761
·
1 Parent(s): 87cd86c

Change tokenizer v1.4

Browse files
Files changed (1) hide show
  1. core/interviewer.py +15 -10
core/interviewer.py CHANGED
@@ -1,25 +1,33 @@
1
  # core/interviewer.py
2
  """
3
  🇬🇧 Interviewer logic module (no instructions)
4
- Generates random MBTI-style questions using a fine-tuned model.
5
 
6
  🇷🇺 Модуль интервьюера.
7
- Использует fine-tuned модель для генерации вопросов без промптов и инструкций.
8
  """
 
 
 
 
9
  from transformers import AutoModelForSeq2SeqLM, T5Tokenizer
10
 
 
 
 
11
  QG_MODEL = "f3nsmart/ft-flan-t5-base-qgen"
12
 
 
13
  tokenizer = T5Tokenizer.from_pretrained(QG_MODEL, use_fast=False)
14
  model = AutoModelForSeq2SeqLM.from_pretrained(QG_MODEL)
15
 
16
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
  model.to(device).eval()
18
-
19
  print(f"✅ Loaded interviewer model (slow tokenizer): {QG_MODEL}")
 
20
 
21
  # --------------------------------------------------------------
22
- # 2️⃣ Базовые seed-промпты (без инструкций)
23
  # --------------------------------------------------------------
24
  PROMPTS = [
25
  "Personality and emotions.",
@@ -33,7 +41,7 @@ PROMPTS = [
33
  # 3️⃣ Очистка текста
34
  # --------------------------------------------------------------
35
  def _clean_question(text: str) -> str:
36
- """Берёт первую фразу с '?', обрезает лишнее"""
37
  text = text.strip()
38
  m = re.search(r"(.+?\?)", text)
39
  if m:
@@ -50,9 +58,7 @@ def _clean_question(text: str) -> str:
50
  # 4️⃣ Генерация вопроса
51
  # --------------------------------------------------------------
52
  def generate_question(user_id: str = "default_user", **kwargs) -> str:
53
- """
54
- Генерирует один MBTI-вопрос без инструкций.
55
- """
56
  prompt = random.choice(PROMPTS)
57
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True).to(device)
58
  with torch.no_grad():
@@ -65,5 +71,4 @@ def generate_question(user_id: str = "default_user", **kwargs) -> str:
65
  max_new_tokens=60,
66
  )
67
  text = tokenizer.decode(out[0], skip_special_tokens=True)
68
- question = _clean_question(text)
69
- return question
 
1
  # core/interviewer.py
2
  """
3
  🇬🇧 Interviewer logic module (no instructions)
4
+ Generates random MBTI-style questions using the fine-tuned model.
5
 
6
  🇷🇺 Модуль интервьюера.
7
+ Использует fine-tuned модель для генерации вопросов без инструкций.
8
  """
9
+
10
+ import random
11
+ import re
12
+ import torch
13
  from transformers import AutoModelForSeq2SeqLM, T5Tokenizer
14
 
15
+ # --------------------------------------------------------------
16
+ # 1️⃣ Настройки модели
17
+ # --------------------------------------------------------------
18
  QG_MODEL = "f3nsmart/ft-flan-t5-base-qgen"
19
 
20
+ # ✅ Принудительно используем оригинальный SentencePiece-токенайзер
21
  tokenizer = T5Tokenizer.from_pretrained(QG_MODEL, use_fast=False)
22
  model = AutoModelForSeq2SeqLM.from_pretrained(QG_MODEL)
23
 
24
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
25
  model.to(device).eval()
 
26
  print(f"✅ Loaded interviewer model (slow tokenizer): {QG_MODEL}")
27
+ print(f"Device set to use {device}")
28
 
29
  # --------------------------------------------------------------
30
+ # 2️⃣ Seed-промпты (без инструкций)
31
  # --------------------------------------------------------------
32
  PROMPTS = [
33
  "Personality and emotions.",
 
41
  # 3️⃣ Очистка текста
42
  # --------------------------------------------------------------
43
  def _clean_question(text: str) -> str:
44
+ """Берёт первую фразу с '?'"""
45
  text = text.strip()
46
  m = re.search(r"(.+?\?)", text)
47
  if m:
 
58
  # 4️⃣ Генерация вопроса
59
  # --------------------------------------------------------------
60
  def generate_question(user_id: str = "default_user", **kwargs) -> str:
61
+ """Генерирует один MBTI-вопрос без инструкций"""
 
 
62
  prompt = random.choice(PROMPTS)
63
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True).to(device)
64
  with torch.no_grad():
 
71
  max_new_tokens=60,
72
  )
73
  text = tokenizer.decode(out[0], skip_special_tokens=True)
74
+ return _clean_question(text)