refac: similarity operation

This commit is contained in:
Timothy J. Baek 2024-10-23 22:38:58 -07:00
parent cde33002c7
commit d7151fe6fa

View File

@ -7,7 +7,7 @@
import * as ort from 'onnxruntime-web'; import * as ort from 'onnxruntime-web';
import { AutoModel, AutoTokenizer } from '@huggingface/transformers'; import { AutoModel, AutoTokenizer } from '@huggingface/transformers';
const embedding_model = 'TaylorAI/bge-micro-v2'; const EMBEDDING_MODEL = 'TaylorAI/bge-micro-v2';
let tokenizer = null; let tokenizer = null;
let model = null; let model = null;
@ -128,9 +128,6 @@
case '1': case '1':
outcome = 1; outcome = 1;
break; break;
case '0':
outcome = 0.5;
break;
case '-1': case '-1':
outcome = 0; outcome = 0;
break; break;
@ -138,9 +135,10 @@
return; // Skip invalid ratings return; // Skip invalid ratings
} }
const similarity = similarities.get(feedback.id) || 1; // If the query is empty, set similarity to 1, else get the similarity from the map
const similarity = query !== '' ? similarities.get(feedback.id) || 0 : 1;
const opponents = feedback.data.sibling_model_ids || []; const opponents = feedback.data.sibling_model_ids || [];
opponents.forEach((modelB) => { opponents.forEach((modelB) => {
const statsB = getOrDefaultStats(modelB); const statsB = getOrDefaultStats(modelB);
const changeA = calculateEloChange(statsA.rating, statsB.rating, outcome, similarity); const changeA = calculateEloChange(statsA.rating, statsB.rating, outcome, similarity);
@ -270,8 +268,8 @@
feedbacks = await getAllFeedbacks(localStorage.token); feedbacks = await getAllFeedbacks(localStorage.token);
loaded = true; loaded = true;
tokenizer = await AutoTokenizer.from_pretrained(embedding_model); tokenizer = await AutoTokenizer.from_pretrained(EMBEDDING_MODEL);
model = await AutoModel.from_pretrained(embedding_model); model = await AutoModel.from_pretrained(EMBEDDING_MODEL);
// Pre-compute embeddings for all unique tags // Pre-compute embeddings for all unique tags
const allTags = new Set(feedbacks.flatMap((feedback) => feedback.data.tags || [])); const allTags = new Set(feedbacks.flatMap((feedback) => feedback.data.tags || []));