Update README.md
Browse files
README.md
CHANGED
@@ -1,73 +1,85 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
-
|
9 |
-
|
10 |
-
|
11 |
-
-
|
12 |
-
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# AskBit FAQ Classifier
|
15 |
|
16 |
-
A
|
17 |
|
18 |
-
> π This model was created as part of an educational
|
19 |
|
20 |
-
* π’ Uses
|
21 |
-
* π§
|
22 |
-
*
|
|
|
|
|
|
|
23 |
|
24 |
---
|
25 |
|
26 |
## π Files in This Repository
|
27 |
|
28 |
-
| File
|
29 |
-
|
30 |
-
| `
|
31 |
-
| `
|
32 |
-
| `
|
|
|
33 |
|
34 |
---
|
35 |
|
36 |
## π§ How It Works
|
37 |
|
38 |
-
### Bit Vector Encoding (`
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
-
###
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
---
|
51 |
|
52 |
## π Usage Example
|
53 |
|
54 |
-
```
|
55 |
import pickle
|
56 |
import numpy as np
|
57 |
|
58 |
-
# Load model
|
59 |
-
with open("
|
60 |
model = pickle.load(f)
|
61 |
|
62 |
-
# Bit vector input
|
63 |
-
query_vec = np.array([1, 0, 1, 1, 0, ..., 0]) #
|
64 |
|
65 |
-
# Predict
|
66 |
answer = model.predict(query_vec)
|
67 |
print("Predicted answer:", answer)
|
68 |
```
|
69 |
|
70 |
-
> β οΈ
|
71 |
|
72 |
---
|
73 |
|
@@ -75,14 +87,17 @@ print("Predicted answer:", answer)
|
|
75 |
|
76 |
Install dependencies with:
|
77 |
|
78 |
-
```
|
79 |
pip install -r requirements.txt
|
80 |
```
|
81 |
|
82 |
-
Main
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
86 |
|
87 |
---
|
88 |
|
@@ -90,9 +105,9 @@ Main requirements:
|
|
90 |
|
91 |
This model is part of the [AskBit project on GitHub](https://github.com/Shanvit7/askbit):
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
|
97 |
---
|
98 |
|
@@ -104,6 +119,6 @@ MIT License β free to use, modify, or contribute.
|
|
104 |
|
105 |
## π€ Contributing
|
106 |
|
107 |
-
This model is
|
108 |
|
109 |
> Model trained and shared by [@Shanvit](https://huggingface.co/Shanvit)
|
|
|
1 |
+
---
|
2 |
+
|
3 |
+
license: mit
|
4 |
+
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
|
8 |
+
pipeline_tag: text-classification
|
9 |
+
|
10 |
+
tags:
|
11 |
+
- faqs
|
12 |
+
- bitwise
|
13 |
+
- semantic-search
|
14 |
+
- knn
|
15 |
+
- sbert
|
16 |
+
- bit-vector
|
17 |
+
- binary-embedding
|
18 |
+
|
19 |
+
---
|
20 |
+
|
21 |
# AskBit FAQ Classifier
|
22 |
|
23 |
+
A fast, interpretable FAQ retriever using **bit vector encoding of SBERT sentence embeddings** combined with a **binary KNN classifier**. This repository hosts a **model artifact** from the [AskBit](https://github.com/Shanvit7/askbit) project.
|
24 |
|
25 |
+
> π This model was created as part of an educational journey exploring efficient semantic FAQ matching with bitwise vector representations and KNN classification.
|
26 |
|
27 |
+
* π’ Uses SBERT (`all-MiniLM-L6-v2`) to embed question-answer pairs as dense semantic vectors.
|
28 |
+
* π§ Converts dense embeddings into binarized bit vectors for fast similarity search.
|
29 |
+
* β‘ Uses a K-Nearest Neighbors classifier with Hamming distance over bit vectors.
|
30 |
+
* π‘ Fully open source, efficient, and suitable for lightweight semantic FAQ retrieval.
|
31 |
+
* ποΈ Model file: `model.pkl`
|
32 |
+
* π Training data file: `faq.json`
|
33 |
|
34 |
---
|
35 |
|
36 |
## π Files in This Repository
|
37 |
|
38 |
+
| File | Description |
|
39 |
+
|---------------------|--------------------------------------------------------------|
|
40 |
+
| `model.pkl` | Trained KNN classifier model over SBERT-based bit vectors. |
|
41 |
+
| `faq.json` | FAQ question-answer dataset used for training and evaluation.|
|
42 |
+
| `requirements.txt` | Python dependencies to load and use the model. |
|
43 |
+
| `README.md` | Model usage instructions, background, and examples. |
|
44 |
|
45 |
---
|
46 |
|
47 |
## π§ How It Works
|
48 |
|
49 |
+
### Semantic Bit Vector Encoding (`SbertBitEncoder`)
|
50 |
|
51 |
+
- Uses the **Sentence-BERT** model (`all-MiniLM-L6-v2`) to generate dense semantic embeddings of entire question-answer pairs.
|
52 |
+
- Embeddings capture **meaningful sentence-level semantics**, enabling effective retrieval beyond simple word overlap.
|
53 |
+
- Each dense embedding vector is **binarized** by thresholding (e.g., bits set to 1 if value > 0) to produce a compact, fixed-length bit vector.
|
54 |
+
- Both the FAQ entries and queries are encoded this way, ensuring semantic similarity maps to bitwise proximity.
|
55 |
|
56 |
+
### Binary K-Nearest Neighbors Classifier (`FAQClassifier`)
|
57 |
|
58 |
+
- Implements a KNN classifier using **Hamming distance** as the similarity metric on bit vectors.
|
59 |
+
- Learns to associate bit-encoded queries with their corresponding answers.
|
60 |
+
- Supports retrieving the best matching answer or top-k candidates with similarity scores.
|
61 |
|
62 |
---
|
63 |
|
64 |
## π Usage Example
|
65 |
|
66 |
+
```
|
67 |
import pickle
|
68 |
import numpy as np
|
69 |
|
70 |
+
# Load the trained model artifact
|
71 |
+
with open("model.pkl", "rb") as f:
|
72 |
model = pickle.load(f)
|
73 |
|
74 |
+
# Bit vector input: binarized SBERT embeddings (e.g., 384-bit vector)
|
75 |
+
query_vec = np.array([1, 0, 1, 1, 0, ..., 0]) # Must match training bit vector format
|
76 |
|
77 |
+
# Predict (get best matching answer)
|
78 |
answer = model.predict(query_vec)
|
79 |
print("Predicted answer:", answer)
|
80 |
```
|
81 |
|
82 |
+
> β οΈ Important: Ensure you encode new queries with the same SBERT bit-vector encoder used at training for consistent results.
|
83 |
|
84 |
---
|
85 |
|
|
|
87 |
|
88 |
Install dependencies with:
|
89 |
|
90 |
+
```
|
91 |
pip install -r requirements.txt
|
92 |
```
|
93 |
|
94 |
+
Main dependencies:
|
95 |
|
96 |
+
- `sentence-transformers`
|
97 |
+
- `scikit-learn`
|
98 |
+
- `numpy`
|
99 |
+
- `yake`
|
100 |
+
- `spacy` (for optional text preprocessing)
|
101 |
|
102 |
---
|
103 |
|
|
|
105 |
|
106 |
This model is part of the [AskBit project on GitHub](https://github.com/Shanvit7/askbit):
|
107 |
|
108 |
+
- β
Full source code with CLI and training scripts
|
109 |
+
- β
Debug and inspect bit vectors and retrieval results
|
110 |
+
- β
Lightweight, interpretable semantic FAQ search
|
111 |
|
112 |
---
|
113 |
|
|
|
119 |
|
120 |
## π€ Contributing
|
121 |
|
122 |
+
This model is intended for learning and experimentation. Feel free to fork, improve, or build upon it!
|
123 |
|
124 |
> Model trained and shared by [@Shanvit](https://huggingface.co/Shanvit)
|