Compare commits

..

2 Commits

Author SHA1 Message Date
Oleg Zakharov 32ae109f66 v6 2024-10-18 00:08:45 +03:00
Oleg Zakharov 9b834330af v6 2024-10-18 00:07:19 +03:00
10 changed files with 34 additions and 13 deletions

Binary file not shown.

Binary file not shown.

View File

@ -37,7 +37,7 @@ class Qwen(BaseModel):
self.max_tokens = max_tokens self.max_tokens = max_tokens
self.messages = [] self.messages = []
def ask(self, user_message: str, clear_history: bool = True) -> Optional[str]: def ask(self, user_message: str, clear_history: bool = True, debug: bool = False) -> Optional[str]:
if clear_history: if clear_history:
self.messages = [] self.messages = []
if self.system_prompt: if self.system_prompt:
@ -47,6 +47,9 @@ class Qwen(BaseModel):
prompt_text = self._build_prompt() prompt_text = self._build_prompt()
if debug:
print(prompt_text)
inputs = self.tokenizer(prompt_text, return_tensors="pt").to(self.device) inputs = self.tokenizer(prompt_text, return_tensors="pt").to(self.device)
with torch.no_grad(): with torch.no_grad():

View File

@ -1,9 +1,27 @@
import pandas as pd import pandas as pd
def preprocess_test(test_solutions_path: str, test_tasks_path: str, save_path: str) -> None: def preprocess_test(test_solutions_path: str, test_tasks_path: str, test_tests_path: str, save_path: str) -> None:
solutions_df = pd.read_excel(test_solutions_path) solutions_df = pd.read_excel(test_solutions_path)
tasks_df = pd.read_excel(test_tasks_path) tasks_df = pd.read_excel(test_tasks_path)
tests_df = pd.read_excel(test_tests_path)
preprocessed_df = solutions_df.merge(tasks_df[['id', 'description']], left_on='task_id', right_on='id', how='left') preprocessed_df = solutions_df.merge(tasks_df[['id', 'description', 'author_solution']],
left_on='task_id', right_on='id', how='left')
preprocessed_df[['description', 'student_solution']].to_excel(save_path, index=False) preprocessed_df = preprocessed_df.merge(tests_df[['task_id', 'input', 'output']],
left_on='task_id', right_on='task_id', how='left')
preprocessed_df['input_output'] = preprocessed_df.apply(
lambda row: f"{row['input']}-{row['output']}" if pd.notna(row['input']) or pd.notna(row['output']) else "",
axis=1
)
grouped_df = preprocessed_df.groupby('id_x').agg({
'student_solution': 'first',
'description': 'first',
'author_solution': 'first',
'input_output': lambda x: '\n'.join(filter(None, x))
}).reset_index()
grouped_df = grouped_df.rename(columns={'id_x': 'id'})
grouped_df.to_excel(save_path, index=False)

View File

@ -40,9 +40,9 @@ def generate_submit(tests_path: str, predict_func: Callable, save_path: str, use
idx = tests.index[i] idx = tests.index[i]
solution_row = tests.iloc[i] solution_row = tests.iloc[i]
input_text = f"{solution_row['description']}\n\n{solution_row['student_solution']}" input_text = f"Вводные данные:\n{solution_row['description']}\n\nКод студента:\n{solution_row['student_solution']}\n\nКод автора:\n{solution_row['author_solution']}\n\nТестовые условия:\n{solution_row['input_output']}"
text = predict_func(input_text) text = predict_func(input_text)
embedding = embedding2string(get_sentence_embedding(text)) embedding = embedding2string(get_sentence_embedding(text))
submit_df.loc[i] = [i, text, embedding] submit_df.loc[i] = [solution_row['id'], text, embedding]
submit_df.to_csv(save_path, index=False) submit_df.to_csv(save_path, index=False)

Binary file not shown.

View File

@ -18,7 +18,7 @@ if __name__ == "__main__":
system_prompt=system_prompt, system_prompt=system_prompt,
) )
preprocess_test("data/raw/test/solutions.xlsx", "data/raw/test/tasks.xlsx", "data/processed/test.xlsx") preprocess_test("data/raw/test/solutions.xlsx", "data/raw/test/tasks.xlsx", "data/raw/test/tests.xlsx", "data/processed/test.xlsx")
# Predict, ёмаё) # Predict, ёмаё)
def predict(input_text: str) -> str: def predict(input_text: str) -> str: