Datasets:
Update README with LanceDB examples
Browse files
README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
license: mit
|
| 3 |
task_categories:
|
| 4 |
- image-classification
|
| 5 |
-
- image-
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
tags:
|
|
@@ -98,6 +98,28 @@ neighbors = ds.scanner(
|
|
| 98 |
print(neighbors)
|
| 99 |
```
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
## Filter by class
|
| 102 |
|
| 103 |
```python
|
|
@@ -106,6 +128,22 @@ ds = lance.dataset("hf://datasets/lance-format/cifar10-lance/data/train.lance")
|
|
| 106 |
ships = ds.scanner(filter="label_name = 'ship'", columns=["id"], limit=5).to_table()
|
| 107 |
```
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
## Working with images
|
| 110 |
|
| 111 |
```python
|
|
|
|
| 2 |
license: mit
|
| 3 |
task_categories:
|
| 4 |
- image-classification
|
| 5 |
+
- image-feature-extraction
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
tags:
|
|
|
|
| 98 |
print(neighbors)
|
| 99 |
```
|
| 100 |
|
| 101 |
+
### LanceDB vector search
|
| 102 |
+
|
| 103 |
+
```python
|
| 104 |
+
import lancedb
|
| 105 |
+
|
| 106 |
+
db = lancedb.connect("hf://datasets/lance-format/cifar10-lance/data")
|
| 107 |
+
tbl = db.open_table("train")
|
| 108 |
+
|
| 109 |
+
ref = tbl.search().limit(1).select(["image_emb"]).to_list()[0]
|
| 110 |
+
query_embedding = ref["image_emb"]
|
| 111 |
+
|
| 112 |
+
results = (
|
| 113 |
+
tbl.search(query_embedding)
|
| 114 |
+
.metric("cosine")
|
| 115 |
+
.select(["id", "label_name"])
|
| 116 |
+
.limit(5)
|
| 117 |
+
.to_list()
|
| 118 |
+
)
|
| 119 |
+
for row in results:
|
| 120 |
+
print(row["id"], row["label_name"])
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
## Filter by class
|
| 124 |
|
| 125 |
```python
|
|
|
|
| 128 |
ships = ds.scanner(filter="label_name = 'ship'", columns=["id"], limit=5).to_table()
|
| 129 |
```
|
| 130 |
|
| 131 |
+
### Filter by class with LanceDB
|
| 132 |
+
|
| 133 |
+
```python
|
| 134 |
+
import lancedb
|
| 135 |
+
|
| 136 |
+
db = lancedb.connect("hf://datasets/lance-format/cifar10-lance/data")
|
| 137 |
+
tbl = db.open_table("train")
|
| 138 |
+
ships = (
|
| 139 |
+
tbl.search()
|
| 140 |
+
.where("label_name = 'ship'")
|
| 141 |
+
.select(["id"])
|
| 142 |
+
.limit(5)
|
| 143 |
+
.to_list()
|
| 144 |
+
)
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
## Working with images
|
| 148 |
|
| 149 |
```python
|