MCPcopy Create free account
hub / github.com/feast-dev/feast / bootstrap

Function bootstrap

sdk/python/feast/templates/pytorch_nlp/bootstrap.py:249–301  ·  view source on GitHub ↗

Bootstrap the pytorch_nlp template with sample data.

()

Source from the content-addressed store, hash-verified

247
248
249def bootstrap():
250 """Bootstrap the pytorch_nlp template with sample data."""
251 repo_path = pathlib.Path(__file__).parent.absolute() / "feature_repo"
252 raw_project_name = pathlib.Path(__file__).parent.absolute().name
253
254 # Sanitize project name for SQLite compatibility (no hyphens allowed)
255 project_name = raw_project_name.replace("-", "_")
256 if project_name != raw_project_name:
257 print(f" ℹ️ Project name sanitized: '{raw_project_name}' → '{project_name}'")
258 print(" 💡 SQLite table names cannot contain hyphens")
259
260 data_path = repo_path / "data"
261 data_path.mkdir(exist_ok=True)
262
263 print("🎭 Setting up sentiment analysis data for PyTorch NLP demonstration...")
264
265 parquet_file = data_path / "sentiment_data.parquet"
266
267 # Generate sentiment data
268 print(" 📝 Generating synthetic sentiment analysis dataset...")
269 df = create_sentiment_data(num_samples=1000)
270
271 # Save to parquet
272 table = pa.Table.from_pandas(df)
273 pq.write_table(table, parquet_file)
274
275 print(f" ✅ Created sentiment dataset with {len(df)} samples")
276 print(" 📊 Sentiment distribution:")
277 sentiment_counts = df["sentiment_label"].value_counts()
278 for sentiment, count in sentiment_counts.items():
279 print(f" - {sentiment.capitalize()}: {count} samples")
280
281 # Replace template placeholders
282 example_py_file = repo_path / "example_repo.py"
283 replace_str_in_file(example_py_file, "%PROJECT_NAME%", str(project_name))
284
285 test_workflow_file = repo_path / "test_workflow.py"
286 replace_str_in_file(test_workflow_file, "%PROJECT_NAME%", str(project_name))
287
288 print("🚀 PyTorch NLP template initialized successfully!")
289
290 print("\n🎯 To get started:")
291 print(f" 1. cd {project_name}")
292 print(" 2. pip install -r requirements.txt")
293 print(" 3. cd feature_repo")
294 print(" 4. feast apply")
295 print(" 5. feast materialize")
296 print(" 6. python test_workflow.py")
297 print("\n💡 This template demonstrates:")
298 print(" - Text feature engineering with Feast")
299 print(" - PyTorch + Hugging Face transformers integration")
300 print(" - Sentiment analysis with pre-trained models")
301 print(" - Online and offline feature serving")
302
303
304if __name__ == "__main__":

Callers 1

bootstrap.pyFile · 0.70

Calls 4

replace_str_in_fileFunction · 0.90
create_sentiment_dataFunction · 0.85
write_tableMethod · 0.80
from_pandasMethod · 0.45

Tested by

no test coverage detected