Update README.md
Browse files
README.md
CHANGED
@@ -34,6 +34,51 @@ Each record in the dataset represents a news article about technology companies
|
|
34 |
- description: A brief summary of the news article's content.
|
35 |
- embedding: An array of numerical values representing the vector embedding for the article, generated using the OpenAI EMBEDDING_MODEL.
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
## Usage
|
38 |
The dataset is suited for a range of applications, including:
|
39 |
|
|
|
34 |
- description: A brief summary of the news article's content.
|
35 |
- embedding: An array of numerical values representing the vector embedding for the article, generated using the OpenAI EMBEDDING_MODEL.
|
36 |
|
37 |
+
|
38 |
+
## Data Ingestion
|
39 |
+
[Create a free MongoDB Atlas Account](https://www.mongodb.com/cloud/atlas/register?utm_campaign=devrel&utm_source=community&utm_medium=organic_social&utm_content=Hugging%20Face%20Dataset&utm_term=richmond.alake) and conduct the Data Ingestion process below.
|
40 |
+
|
41 |
+
```python
|
42 |
+
import os
|
43 |
+
from pymongo import MongoClient
|
44 |
+
import datasets
|
45 |
+
from datasets import load_dataset
|
46 |
+
from bson import json_util
|
47 |
+
|
48 |
+
# MongoDB Atlas URI and client setup
|
49 |
+
uri = os.environ.get('MONGODB_ATLAS_URI')
|
50 |
+
client = MongoClient(uri)
|
51 |
+
|
52 |
+
# Change to the appropriate database and collection names for the tech news embeddings
|
53 |
+
db_name = 'your_database_name' # Change this to your actual database name
|
54 |
+
collection_name = 'tech_news_embeddings' # Change this to your actual collection name
|
55 |
+
|
56 |
+
tech_news_embeddings_collection = client[db_name][collection_name]
|
57 |
+
|
58 |
+
# Load the "tech-news-embeddings" dataset from Hugging Face
|
59 |
+
dataset = load_dataset("AIatMongoDB/tech-news-embeddings")
|
60 |
+
|
61 |
+
insert_data = []
|
62 |
+
|
63 |
+
# Iterate through the dataset and prepare the documents for insertion
|
64 |
+
for item in dataset['train']:
|
65 |
+
# Convert the dataset item to MongoDB document format
|
66 |
+
doc_item = json_util.loads(json_util.dumps(item))
|
67 |
+
insert_data.append(doc_item)
|
68 |
+
|
69 |
+
# Insert in batches of 1000 documents
|
70 |
+
if len(insert_data) == 1000:
|
71 |
+
tech_news_embeddings_collection.insert_many(insert_data)
|
72 |
+
print("1000 records ingested")
|
73 |
+
insert_data = []
|
74 |
+
|
75 |
+
# Insert any remaining documents
|
76 |
+
if len(insert_data) > 0:
|
77 |
+
tech_news_embeddings_collection.insert_many(insert_data)
|
78 |
+
print("Data Ingested")
|
79 |
+
|
80 |
+
```
|
81 |
+
|
82 |
## Usage
|
83 |
The dataset is suited for a range of applications, including:
|
84 |
|