Spaces:
Sleeping

PavanKumarD commited on
Commit
63c38c6
·
1 Parent(s): 1320523

Add full project with model and app

Browse files
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+
2
+ OPENROUTER_API_KEYS= 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,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,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,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,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
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # Install basic dependencies
4
+ RUN apt-get update && apt-get install -y \
5
+ libgl1-mesa-glx \
6
+ libglib2.0-0 \
7
+ && rm -rf /var/lib/apt/lists/*
8
+
9
+ # Set working directory
10
+ WORKDIR /code
11
+
12
+ # Copy files
13
+ COPY . .
14
+
15
+ # Install Python dependencies
16
+ RUN pip install --upgrade pip
17
+ RUN pip install -r requirements.txt
18
+
19
+ # Expose API on port 7860
20
+ EXPOSE 7860
21
+
22
+ # Run FastAPI app
23
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app/backend.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import fitz # PyMuPDF
3
+ import faiss
4
+ import numpy as np
5
+ import traceback
6
+ from dotenv import load_dotenv
7
+ from openai import OpenAI
8
+ from sentence_transformers import SentenceTransformer
9
+
10
+ # Load environment variables
11
+ load_dotenv()
12
+ # Global variable to cache last successful API index during runtime
13
+ current_api_index = 0
14
+
15
+ # ✅ Load multiple OpenRouter API keys from environment
16
+ openrouter_keys = os.getenv("OPENROUTER_API_KEYS", "").split(",")
17
+
18
+ # ✅ Preferred model
19
+ # MODEL_NAME = "deepseek/deepseek-r1-0528-qwen3-8b:free"
20
+ # MODEL_NAME = "qwen/qwen3-4b:free"
21
+ MODEL_NAME = "qwen/qwen-2.5-72b-instruct:free"
22
+ # MODEL_NAME = "google/gemma-3-12b-it:free"
23
+
24
+ # ✅ Load sentence embedding model
25
+ embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
26
+
27
+
28
+ # ✅ Step 1: Extract text from PDF
29
+ def extract_text_from_pdf(pdf_path):
30
+ doc = fitz.open(pdf_path)
31
+ return " ".join([page.get_text() for page in doc])
32
+
33
+
34
+ # ✅ Step 2: Build FAISS index from text chunks
35
+ def build_faiss_index(text, chunk_size=500):
36
+ chunks = [text[i:i + chunk_size] for i in range(0, len(text), chunk_size)]
37
+ embeddings = embedding_model.encode(chunks)
38
+ index = faiss.IndexFlatL2(embeddings.shape[1])
39
+ index.add(np.array(embeddings))
40
+ return index, chunks
41
+
42
+
43
+ # ✅ Step 3: Generate answer with OpenRouter fallback
44
+ def generate_answer(query, index, chunks, chat_history=None, user_data_text="", top_k=10):
45
+ global current_api_index # Cache index across calls
46
+
47
+ # Vectorize query and retrieve top-k matching chunks
48
+ query_vec = embedding_model.encode([query])
49
+ _, indices = index.search(np.array(query_vec), top_k)
50
+ relevant_chunks = [chunks[i] for i in indices[0] if i < len(chunks)]
51
+
52
+ # Warn if low-quality retrieval
53
+ if not any(relevant_chunks):
54
+ return "⚠️ I'm unable to find any relevant context to answer your question accurately. Please try rephrasing or ask a different question."
55
+
56
+ context = "\n".join(relevant_chunks)
57
+
58
+ # Chat history formatting
59
+ history_block = ""
60
+ if chat_history:
61
+ for turn in chat_history:
62
+ who = "User" if turn["role"] == "user" else "FinBot"
63
+ history_block += f"{who}: {turn['message']}\n"
64
+
65
+ # Optional user-specific data
66
+ user_data_block = f"\n<user_data>\n{user_data_text.strip()}\n</user_data>" if user_data_text else ""
67
+ additional_prompt = "Use the user's name from <user_data> when appropriate. Always prioritize <context> and <user_data> while answering." if user_data_text else ""
68
+
69
+ # Final prompt to model
70
+ prompt = f"""
71
+ <system>
72
+ You are FinBot, a respectful, helpful, and context-aware financial assistant.
73
+ Your answers must be grounded in the provided <context> and <user_data>.
74
+ Do not hallucinate or fabricate. If relevant information is missing, clearly state that.
75
+ But ack as a best friend and give suggestions
76
+ </system>
77
+
78
+ <additional_prompt>
79
+ {additional_prompt}
80
+ </additional_prompt>
81
+
82
+ <chat_history>
83
+ {history_block}
84
+ </chat_history>
85
+
86
+ <context>
87
+ {context}
88
+ </context>
89
+ {user_data_block}
90
+
91
+ <question>
92
+ {query}
93
+ </question>
94
+
95
+ <instructions>
96
+ - Answer precisely using <context> and <user_data>.
97
+ - provide suggestions and actionalble insights also.
98
+ - You have to answer only related to the bank documents you are given in the <context> don,t refer any other banks.
99
+ - If <context> doesn’t contain the answer, say it clearly and suggest possible next steps.
100
+ - if the queries are genral grewints or praisings like that respond with a positive tone.
101
+ - Maintain a professional and empathetic tone.
102
+ - only if the user asks for a specific financial product or service, provide a clear and concise description of it.
103
+ - Never make up information. Never assume. Be transparent.
104
+ - if the query is to compare then give tabular form and explain that as paragraph.
105
+ - at the end ask for few followeing up questions that you think are relevant to the query.
106
+ - Format using Markdown:
107
+ - Use `##`, `###` for headings.
108
+ - Use `**bold**` for highlights.
109
+ - Use `-` for bullet points.
110
+ -
111
+ </instructions>
112
+ """
113
+
114
+ # Try all available API keys
115
+ indices_to_try = [current_api_index] + [i for i in range(len(openrouter_keys)) if i != current_api_index]
116
+
117
+ for idx in indices_to_try:
118
+ api_key = openrouter_keys[idx].strip()
119
+ try:
120
+ print(f"🔑 Trying API Key #{idx + 1}")
121
+ client = OpenAI(
122
+ base_url="https://openrouter.ai/api/v1",
123
+ api_key=api_key
124
+ )
125
+ completion = client.chat.completions.create(
126
+ model=MODEL_NAME,
127
+ messages=[{"role": "user", "content": prompt}],
128
+ extra_headers={
129
+ "HTTP-Referer": "http://localhost:8000",
130
+ "X-Title": "FinBot"
131
+ }
132
+ )
133
+ print(f"✅ Successfully used API Key #{idx + 1}")
134
+ current_api_index = idx # Update cache
135
+ # print("🔍 Raw completion:", completion)
136
+ return completion.choices[0].message.content.strip()
137
+ except Exception as e:
138
+ print(f"❌ Failed with API Key #{idx + 1}: {e}")
139
+ traceback.print_exc()
140
+
141
+ return "❗ All OpenRouter API keys failed. Please try again later."
app/main.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app/main.py
2
+ from fastapi import FastAPI, UploadFile, File, Request, Form
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from fastapi.responses import JSONResponse
5
+ from app.backend import extract_text_from_pdf, build_faiss_index, generate_answer
6
+ import os
7
+ from markdown import markdown as md
8
+ import re
9
+ import faiss
10
+ import numpy as np
11
+ app = FastAPI()
12
+
13
+ def protect_math(text):
14
+ return re.sub(r'(\${2})(.+?)\1', r'@@\2@@', text, flags=re.DOTALL)
15
+
16
+ def unprotect_math(html):
17
+ return html.replace('@@', '$$')
18
+
19
+ def auto_wrap_math_blocks(text):
20
+ def wrap_if_needed(line):
21
+ if re.search(r'\\text|\d+\s*[\+\-\*/=]\s*\d+', line) and not re.match(r'\s*\$\$', line):
22
+ return f"$$\n{line.strip()}\n$$"
23
+ return line
24
+ return "\n".join(wrap_if_needed(l) for l in text.splitlines())
25
+
26
+
27
+ app.add_middleware(
28
+ CORSMiddleware,
29
+ allow_origins=["*"],
30
+ allow_methods=["*"],
31
+ allow_headers=["*"]
32
+ )
33
+
34
+ # ----------- Load Static Banking Documents ------------
35
+ # ✅ Load saved FAISS index
36
+ BASE_DIR = os.path.dirname(__file__)
37
+ index_path = os.path.join(BASE_DIR, "vector_base/faiss_index.bin")
38
+ faiss_index = faiss.read_index(index_path)
39
+
40
+ BASE_DIR = os.path.dirname(__file__)
41
+ faiss_index = faiss.read_index(os.path.join(BASE_DIR, "vector_base", "faiss_index.bin"))
42
+ document_chunks = np.load(os.path.join(BASE_DIR, "vector_base", "chunks.npy"), allow_pickle=True).tolist()
43
+
44
+
45
+
46
+ chat_sessions = {}
47
+
48
+ # -------------- Chat Endpoint ----------------
49
+ @app.post("/query")
50
+ async def query_endpoint(
51
+ request: Request,
52
+ query: str = Form(...),
53
+ user_data_text: str = Form(""), # ✅ Accept dynamic user data
54
+ ):
55
+ client_ip = request.client.host
56
+ chat_history = chat_sessions.get(client_ip, [])
57
+
58
+ # This now only uses dynamic user data
59
+ combined_user_data = user_data_text.strip()
60
+
61
+
62
+ answer = generate_answer(
63
+ query=query,
64
+ index=faiss_index,
65
+ chunks=document_chunks,
66
+ chat_history=chat_history,
67
+ user_data_text=combined_user_data # ✅ Send to LLM
68
+ )
69
+
70
+ chat_history.append({"role": "user", "message": query})
71
+ chat_history.append({"role": "bot", "message": answer})
72
+ chat_sessions[client_ip] = chat_history
73
+ # answer = auto_wrap_math_blocks(answer)
74
+ # markdown_safe = protect_math(answer)
75
+ # html_response = md(
76
+ # answer,
77
+ # extensions=[
78
+ # 'markdown.extensions.extra',
79
+ # 'markdown.extensions.admonition',
80
+ # 'markdown.extensions.codehilite',
81
+ # 'markdown.extensions.fenced_code',
82
+ # 'markdown.extensions.tables',
83
+ # 'markdown.extensions.toc'
84
+ # ]
85
+ # )
86
+ # html_response = unprotect_math(html_response)
87
+ return JSONResponse(content={"response": answer})
88
+
FinBot-api.zip → app/vector_base/chunks.npy RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d57128a8757d56c5dabe809a6d056838cd91a8fdd33535032f82ecacfce47d87
3
- size 151402662
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e08286b9d19af44e0e7118e0de3e1f0f049f9349f697f522b457d1acdf307e6
3
+ size 80858128
app/vector_base/faiss_index.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:772be556e8ddacc0e56b17da81023668998fc153eebe1e2ac7695fc8787190bd
3
+ size 62098989
models/all-MiniLM-L6-v2/1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false,
9
+ "include_prompt": true
10
+ }
models/all-MiniLM-L6-v2/README.md ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ library_name: sentence-transformers
5
+ tags:
6
+ - sentence-transformers
7
+ - feature-extraction
8
+ - sentence-similarity
9
+ - transformers
10
+ datasets:
11
+ - s2orc
12
+ - flax-sentence-embeddings/stackexchange_xml
13
+ - ms_marco
14
+ - gooaq
15
+ - yahoo_answers_topics
16
+ - code_search_net
17
+ - search_qa
18
+ - eli5
19
+ - snli
20
+ - multi_nli
21
+ - wikihow
22
+ - natural_questions
23
+ - trivia_qa
24
+ - embedding-data/sentence-compression
25
+ - embedding-data/flickr30k-captions
26
+ - embedding-data/altlex
27
+ - embedding-data/simple-wiki
28
+ - embedding-data/QQP
29
+ - embedding-data/SPECTER
30
+ - embedding-data/PAQ_pairs
31
+ - embedding-data/WikiAnswers
32
+ pipeline_tag: sentence-similarity
33
+ ---
34
+
35
+
36
+ # all-MiniLM-L6-v2
37
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
38
+
39
+ ## Usage (Sentence-Transformers)
40
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
41
+
42
+ ```
43
+ pip install -U sentence-transformers
44
+ ```
45
+
46
+ Then you can use the model like this:
47
+ ```python
48
+ from sentence_transformers import SentenceTransformer
49
+ sentences = ["This is an example sentence", "Each sentence is converted"]
50
+
51
+ model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
52
+ embeddings = model.encode(sentences)
53
+ print(embeddings)
54
+ ```
55
+
56
+ ## Usage (HuggingFace Transformers)
57
+ Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
58
+
59
+ ```python
60
+ from transformers import AutoTokenizer, AutoModel
61
+ import torch
62
+ import torch.nn.functional as F
63
+
64
+ #Mean Pooling - Take attention mask into account for correct averaging
65
+ def mean_pooling(model_output, attention_mask):
66
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
67
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
68
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
69
+
70
+
71
+ # Sentences we want sentence embeddings for
72
+ sentences = ['This is an example sentence', 'Each sentence is converted']
73
+
74
+ # Load model from HuggingFace Hub
75
+ tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
76
+ model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
77
+
78
+ # Tokenize sentences
79
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
80
+
81
+ # Compute token embeddings
82
+ with torch.no_grad():
83
+ model_output = model(**encoded_input)
84
+
85
+ # Perform pooling
86
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
87
+
88
+ # Normalize embeddings
89
+ sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
90
+
91
+ print("Sentence embeddings:")
92
+ print(sentence_embeddings)
93
+ ```
94
+
95
+ ------
96
+
97
+ ## Background
98
+
99
+ The project aims to train sentence embedding models on very large sentence level datasets using a self-supervised
100
+ contrastive learning objective. We used the pretrained [`nreimers/MiniLM-L6-H384-uncased`](https://huggingface.co/nreimers/MiniLM-L6-H384-uncased) model and fine-tuned in on a
101
+ 1B sentence pairs dataset. We use a contrastive learning objective: given a sentence from the pair, the model should predict which out of a set of randomly sampled other sentences, was actually paired with it in our dataset.
102
+
103
+ We developed this model during the
104
+ [Community week using JAX/Flax for NLP & CV](https://discuss.huggingface.co/t/open-to-the-community-community-week-using-jax-flax-for-nlp-cv/7104),
105
+ organized by Hugging Face. We developed this model as part of the project:
106
+ [Train the Best Sentence Embedding Model Ever with 1B Training Pairs](https://discuss.huggingface.co/t/train-the-best-sentence-embedding-model-ever-with-1b-training-pairs/7354). We benefited from efficient hardware infrastructure to run the project: 7 TPUs v3-8, as well as intervention from Googles Flax, JAX, and Cloud team member about efficient deep learning frameworks.
107
+
108
+ ## Intended uses
109
+
110
+ Our model is intended to be used as a sentence and short paragraph encoder. Given an input text, it outputs a vector which captures
111
+ the semantic information. The sentence vector may be used for information retrieval, clustering or sentence similarity tasks.
112
+
113
+ By default, input text longer than 256 word pieces is truncated.
114
+
115
+
116
+ ## Training procedure
117
+
118
+ ### Pre-training
119
+
120
+ We use the pretrained [`nreimers/MiniLM-L6-H384-uncased`](https://huggingface.co/nreimers/MiniLM-L6-H384-uncased) model. Please refer to the model card for more detailed information about the pre-training procedure.
121
+
122
+ ### Fine-tuning
123
+
124
+ We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each possible sentence pairs from the batch.
125
+ We then apply the cross entropy loss by comparing with true pairs.
126
+
127
+ #### Hyper parameters
128
+
129
+ We trained our model on a TPU v3-8. We train the model during 100k steps using a batch size of 1024 (128 per TPU core).
130
+ We use a learning rate warm up of 500. The sequence length was limited to 128 tokens. We used the AdamW optimizer with
131
+ a 2e-5 learning rate. The full training script is accessible in this current repository: `train_script.py`.
132
+
133
+ #### Training data
134
+
135
+ We use the concatenation from multiple datasets to fine-tune our model. The total number of sentence pairs is above 1 billion sentences.
136
+ We sampled each dataset given a weighted probability which configuration is detailed in the `data_config.json` file.
137
+
138
+
139
+ | Dataset | Paper | Number of training tuples |
140
+ |--------------------------------------------------------|:----------------------------------------:|:--------------------------:|
141
+ | [Reddit comments (2015-2018)](https://github.com/PolyAI-LDN/conversational-datasets/tree/master/reddit) | [paper](https://arxiv.org/abs/1904.06472) | 726,484,430 |
142
+ | [S2ORC](https://github.com/allenai/s2orc) Citation pairs (Abstracts) | [paper](https://aclanthology.org/2020.acl-main.447/) | 116,288,806 |
143
+ | [WikiAnswers](https://github.com/afader/oqa#wikianswers-corpus) Duplicate question pairs | [paper](https://doi.org/10.1145/2623330.2623677) | 77,427,422 |
144
+ | [PAQ](https://github.com/facebookresearch/PAQ) (Question, Answer) pairs | [paper](https://arxiv.org/abs/2102.07033) | 64,371,441 |
145
+ | [S2ORC](https://github.com/allenai/s2orc) Citation pairs (Titles) | [paper](https://aclanthology.org/2020.acl-main.447/) | 52,603,982 |
146
+ | [S2ORC](https://github.com/allenai/s2orc) (Title, Abstract) | [paper](https://aclanthology.org/2020.acl-main.447/) | 41,769,185 |
147
+ | [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) (Title, Body) pairs | - | 25,316,456 |
148
+ | [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) (Title+Body, Answer) pairs | - | 21,396,559 |
149
+ | [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) (Title, Answer) pairs | - | 21,396,559 |
150
+ | [MS MARCO](https://microsoft.github.io/msmarco/) triplets | [paper](https://doi.org/10.1145/3404835.3462804) | 9,144,553 |
151
+ | [GOOAQ: Open Question Answering with Diverse Answer Types](https://github.com/allenai/gooaq) | [paper](https://arxiv.org/pdf/2104.08727.pdf) | 3,012,496 |
152
+ | [Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo-answers-dataset) (Title, Answer) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02-Abstract.html) | 1,198,260 |
153
+ | [Code Search](https://huggingface.co/datasets/code_search_net) | - | 1,151,414 |
154
+ | [COCO](https://cocodataset.org/#home) Image captions | [paper](https://link.springer.com/chapter/10.1007%2F978-3-319-10602-1_48) | 828,395|
155
+ | [SPECTER](https://github.com/allenai/specter) citation triplets | [paper](https://doi.org/10.18653/v1/2020.acl-main.207) | 684,100 |
156
+ | [Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo-answers-dataset) (Question, Answer) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02-Abstract.html) | 681,164 |
157
+ | [Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo-answers-dataset) (Title, Question) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02-Abstract.html) | 659,896 |
158
+ | [SearchQA](https://huggingface.co/datasets/search_qa) | [paper](https://arxiv.org/abs/1704.05179) | 582,261 |
159
+ | [Eli5](https://huggingface.co/datasets/eli5) | [paper](https://doi.org/10.18653/v1/p19-1346) | 325,475 |
160
+ | [Flickr 30k](https://shannon.cs.illinois.edu/DenotationGraph/) | [paper](https://transacl.org/ojs/index.php/tacl/article/view/229/33) | 317,695 |
161
+ | [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) Duplicate questions (titles) | | 304,525 |
162
+ | AllNLI ([SNLI](https://nlp.stanford.edu/projects/snli/) and [MultiNLI](https://cims.nyu.edu/~sbowman/multinli/) | [paper SNLI](https://doi.org/10.18653/v1/d15-1075), [paper MultiNLI](https://doi.org/10.18653/v1/n18-1101) | 277,230 |
163
+ | [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) Duplicate questions (bodies) | | 250,519 |
164
+ | [Stack Exchange](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_xml) Duplicate questions (titles+bodies) | | 250,460 |
165
+ | [Sentence Compression](https://github.com/google-research-datasets/sentence-compression) | [paper](https://www.aclweb.org/anthology/D13-1155/) | 180,000 |
166
+ | [Wikihow](https://github.com/pvl/wikihow_pairs_dataset) | [paper](https://arxiv.org/abs/1810.09305) | 128,542 |
167
+ | [Altlex](https://github.com/chridey/altlex/) | [paper](https://aclanthology.org/P16-1135.pdf) | 112,696 |
168
+ | [Quora Question Triplets](https://quoradata.quora.com/First-Quora-Dataset-Release-Question-Pairs) | - | 103,663 |
169
+ | [Simple Wikipedia](https://cs.pomona.edu/~dkauchak/simplification/) | [paper](https://www.aclweb.org/anthology/P11-2117/) | 102,225 |
170
+ | [Natural Questions (NQ)](https://ai.google.com/research/NaturalQuestions) | [paper](https://transacl.org/ojs/index.php/tacl/article/view/1455) | 100,231 |
171
+ | [SQuAD2.0](https://rajpurkar.github.io/SQuAD-explorer/) | [paper](https://aclanthology.org/P18-2124.pdf) | 87,599 |
172
+ | [TriviaQA](https://huggingface.co/datasets/trivia_qa) | - | 73,346 |
173
+ | **Total** | | **1,170,060,424** |
models/all-MiniLM-L6-v2/config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 1536,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 6,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.51.3",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 30522
25
+ }
models/all-MiniLM-L6-v2/config_sentence_transformers.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "4.1.0",
4
+ "transformers": "4.51.3",
5
+ "pytorch": "2.7.0"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null,
9
+ "similarity_fn_name": "cosine"
10
+ }
models/all-MiniLM-L6-v2/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1377e9af0ca0b016a9f2aa584d6fc71ab3ea6804fae21ef9fb1416e2944057ac
3
+ size 90864192
models/all-MiniLM-L6-v2/modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.models.Normalize"
19
+ }
20
+ ]
models/all-MiniLM-L6-v2/sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 256,
3
+ "do_lower_case": false
4
+ }
models/all-MiniLM-L6-v2/special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
models/all-MiniLM-L6-v2/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
models/all-MiniLM-L6-v2/tokenizer_config.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "max_length": 128,
51
+ "model_max_length": 256,
52
+ "never_split": null,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "[PAD]",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "[SEP]",
58
+ "stride": 0,
59
+ "strip_accents": null,
60
+ "tokenize_chinese_chars": true,
61
+ "tokenizer_class": "BertTokenizer",
62
+ "truncation_side": "right",
63
+ "truncation_strategy": "longest_first",
64
+ "unk_token": "[UNK]"
65
+ }
models/all-MiniLM-L6-v2/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ faiss-cpu
4
+ numpy
5
+ PyMuPDF
6
+ python-dotenv
7
+ openai
8
+ sentence-transformers
9
+ markdown
10
+ python-multipart
runtime.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-3.10.12