Spaces:
Sleeping
Sleeping
Updated Readme
Browse files
README.md
CHANGED
|
@@ -1,70 +1,150 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
-
- zh
|
| 6 |
-
- es
|
| 7 |
-
- fr
|
| 8 |
-
- de
|
| 9 |
-
- ja
|
| 10 |
-
- ko
|
| 11 |
-
- ru
|
| 12 |
-
- ar
|
| 13 |
-
metrics:
|
| 14 |
-
- brier_score
|
| 15 |
-
base_model:
|
| 16 |
-
- Qwen/Qwen3-Embedding-0.6B
|
| 17 |
-
new_version: Qwen/Qwen3-Embedding-0.6B
|
| 18 |
-
pipeline_tag: sentence-similarity
|
| 19 |
-
library_name: sentence-transformers
|
| 20 |
-
tags:
|
| 21 |
-
- code
|
| 22 |
-
- semantic-search
|
| 23 |
-
- multilingual
|
| 24 |
-
- ttrpg
|
| 25 |
-
- classification
|
| 26 |
-
- embeddings
|
| 27 |
-
sdk: gradio
|
| 28 |
emoji: π»
|
| 29 |
-
colorFrom:
|
| 30 |
-
colorTo:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
-
|
| 56 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
|
| 61 |
-
|
| 62 |
-
|
|
| 63 |
-
|
|
| 64 |
-
|
|
| 65 |
-
| **Languages** | 100+ |
|
| 66 |
-
| **Parameters** | 0.6B |
|
| 67 |
-
| **Layers** | 28 |
|
| 68 |
-
| **Normalization** | L2 normalized |
|
| 69 |
-
| **Distance Metric** | Cosine similarity |
|
| 70 |
-
| **MTEB Score** | 70.58 (multilingual) |
|
|
|
|
| 1 |
---
|
| 2 |
+
title: FFEmbeds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
emoji: π»
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.49.1
|
| 8 |
+
license: apache-2.0
|
| 9 |
+
short_description: Qwen 4b Embeddings for Games
|
| 10 |
---
|
| 11 |
+
# π» FF Embeddings API
|
| 12 |
+
|
| 13 |
+
**Powered by Qwen3-Embedding-4B** - Advanced 4B-parameter multilingual embedding model with matryoshka truncation
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
## π Quick Start
|
| 17 |
+
|
| 18 |
+
### Python
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
import requests
|
| 22 |
+
import numpy as np
|
| 23 |
+
|
| 24 |
+
url = "https://YOUR_USERNAME-fairfate-embeddings.hf.space/api/predict"
|
| 25 |
+
|
| 26 |
+
# Generate embeddings
|
| 27 |
+
texts = [
|
| 28 |
+
"Storm King's Thunder - Epic D&D 5E giant-themed adventure",
|
| 29 |
+
"Curse of Strahd - Gothic horror campaign in Ravenloft"
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
response = requests.post(
|
| 33 |
+
url,
|
| 34 |
+
json={
|
| 35 |
+
"data": [texts, True, 1536], # [texts, use_instruction, dimensions]
|
| 36 |
+
"fn_index": 0
|
| 37 |
+
}
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
result = response.json()
|
| 41 |
+
embeddings = np.array(result["data"][0])
|
| 42 |
+
|
| 43 |
+
# Calculate similarity
|
| 44 |
+
def cosine_similarity(a, b):
|
| 45 |
+
return np.dot(a, b) # Already normalized
|
| 46 |
+
|
| 47 |
+
similarity = cosine_similarity(embeddings[0], embeddings[1])
|
| 48 |
+
print(f"Similarity: {similarity:.3f}") # ~0.65 (related but different)
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### TypeScript/JavaScript
|
| 52 |
+
|
| 53 |
+
```typescript
|
| 54 |
+
interface EmbeddingResponse {
|
| 55 |
+
data: number[][][];
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
async function getEmbeddings(
|
| 59 |
+
texts: string[],
|
| 60 |
+
useInstruction: boolean = true,
|
| 61 |
+
dimensions: number = 1536
|
| 62 |
+
): Promise<number[][]> {
|
| 63 |
+
const response = await fetch(
|
| 64 |
+
'https://YOUR_USERNAME-fairfate-embeddings.hf.space/api/predict',
|
| 65 |
+
{
|
| 66 |
+
method: 'POST',
|
| 67 |
+
headers: { 'Content-Type': 'application/json' },
|
| 68 |
+
body: JSON.stringify({
|
| 69 |
+
data: [texts, useInstruction, dimensions],
|
| 70 |
+
fn_index: 0
|
| 71 |
+
})
|
| 72 |
+
}
|
| 73 |
+
);
|
| 74 |
+
|
| 75 |
+
const result: EmbeddingResponse = await response.json();
|
| 76 |
+
return result.data[0];
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Usage
|
| 80 |
+
const embeddings = await getEmbeddings([
|
| 81 |
+
"Pathfinder 2E Core Rulebook",
|
| 82 |
+
"D&D 5E Player's Handbook"
|
| 83 |
+
]);
|
| 84 |
+
|
| 85 |
+
// Calculate cosine similarity (already normalized)
|
| 86 |
+
function cosineSimilarity(a: number[], b: number[]): number {
|
| 87 |
+
return a.reduce((sum, val, i) => sum + val * b[i], 0);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
const similarity = cosineSimilarity(embeddings[0], embeddings[1]);
|
| 91 |
+
console.log(`Similarity: ${similarity.toFixed(3)}`); // ~0.78 (both RPG rulebooks)
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### cURL
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
curl -X POST \
|
| 98 |
+
https://YOUR_USERNAME-fairfate-embeddings.hf.space/api/predict \
|
| 99 |
+
-H "Content-Type: application/json" \
|
| 100 |
+
-d '{
|
| 101 |
+
"data": [
|
| 102 |
+
["Cyberpunk detective noir campaign for Shadowrun"],
|
| 103 |
+
true,
|
| 104 |
+
1536
|
| 105 |
+
],
|
| 106 |
+
"fn_index": 0
|
| 107 |
+
}'
|
| 108 |
+
```
|
| 109 |
|
| 110 |
+
## π API Reference
|
| 111 |
|
| 112 |
+
### Endpoint
|
| 113 |
|
| 114 |
+
```
|
| 115 |
+
POST /api/predict
|
| 116 |
+
```
|
| 117 |
|
| 118 |
+
### Request Format
|
| 119 |
|
| 120 |
+
```json
|
| 121 |
+
{
|
| 122 |
+
"data": [
|
| 123 |
+
["text1", "text2", ...], // Array of texts to embed
|
| 124 |
+
true, // use_instruction (boolean)
|
| 125 |
+
1536 // output_dimensions (32-3584, production: 1536)
|
| 126 |
+
],
|
| 127 |
+
"fn_index": 0
|
| 128 |
+
}
|
| 129 |
+
```
|
| 130 |
|
| 131 |
+
### Response Format
|
| 132 |
|
| 133 |
+
```json
|
| 134 |
+
{
|
| 135 |
+
"data": [
|
| 136 |
+
[
|
| 137 |
+
[0.123, -0.456, 0.789, ...], // First embedding (1536 dims)
|
| 138 |
+
[-0.234, 0.567, -0.890, ...] // Second embedding (1536 dims)
|
| 139 |
+
]
|
| 140 |
+
]
|
| 141 |
+
}
|
| 142 |
+
```
|
| 143 |
|
| 144 |
+
### Parameters
|
| 145 |
|
| 146 |
+
| Parameter | Type | Default | Range | Description |
|
| 147 |
+
|-----------|------|---------|-------|-------------|
|
| 148 |
+
| `texts` | string[] | required | - | Texts to embed |
|
| 149 |
+
| `use_instruction` | boolean | true | - | Add instruction prefix (recommended) |
|
| 150 |
+
| `output_dimensions` | number | 1536 | 32-2560 | Output embedding size (production: 1536) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|