{"id":19373610,"url":"https://github.com/4ai/embedding_features","last_synced_at":"2025-06-13T17:32:40.838Z","repository":{"id":130300420,"uuid":"174652068","full_name":"4AI/embedding_features","owner":"4AI","description":null,"archived":false,"fork":false,"pushed_at":"2019-03-24T05:33:34.000Z","size":194,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T17:44:49.121Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/4AI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-09T05:22:18.000Z","updated_at":"2022-12-07T09:52:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a29370a-b3b8-4eb8-b482-8fc5a3aea7ae","html_url":"https://github.com/4AI/embedding_features","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/4AI/embedding_features","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4AI%2Fembedding_features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4AI%2Fembedding_features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4AI%2Fembedding_features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4AI%2Fembedding_features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/4AI","download_url":"https://codeload.github.com/4AI/embedding_features/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4AI%2Fembedding_features/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259688368,"owners_count":22896393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T08:30:15.450Z","updated_at":"2025-06-13T17:32:40.803Z","avatar_url":"https://github.com/4AI.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# embedding_features\n\n\u003e A library to extract word embedding features to train your linear model. \n\u003e We give a sklearn-like api that you can easily combine it with sklearn models.\n\n# Algorithms\n\nThe embedding algorithms we suppoort:\n\n- [x] word2vec\n- [x] fasttext\n\n`word2vec` and `fasttext` are implemented by [gensim](https://github.com/RaRe-Technologies/gensim)\n\n## parameters\n\n### Word2vecFeature\n\n```python\nembedding_features.fasttext.Word2vecFeature (\n    n_dim=100,  # embedding size \n    min_count=1, # min frequency of token\n    window=5,  # context window\n    n_jobs=-1,  # workers\n    pretrained_file=None,  # pretrained word2vec binary model file\n    save_file=None  # path to save trained word2vec model\n)\n```\n\n### FasttextFeature\n\n```python\nembedding_features.fasttext.FasttextFeature (\n    n_dim=100,  # embedding size \n    min_count=1, # min frequency of token\n    window=5,  # context window\n    n_jobs=-1,  # workers\n    pretrained_file=None,  # pretrained word2vec binary model file\n    save_file=None  # path to save trained word2vec model\n)\n```\n\n# Install\n\n```bash\ngit clone https://github.com/4AI/embedding_features.git\ncd embedding_features\npython setup.py install\n```\n\n# Get Started\n\nTo get embedding features, import specific embedding features  from  `embedding_features` and prepare input data.\n\n```python\nfrom embedding_features.fasttext import FasttextFeature\n\nX, y = load_data('examples/corpus/mpqa.txt')\n```\n\nMaybe you want to split you data into train and test dataset, we can easily implement this with sklearn.\n\n```python\nfrom sklearn.model_selection import train_test_split\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n```\n\nNow we can fit the embedding features\n\n```python\nfea = FasttextFeature()\nfea.fit(X_train)\n```\n\nThe same as sklearn, you can fit and transform in the same time.\n\n```python\ntrain_vecs = fea.fit_transform(X_train)\n```\n\nAfter `fit` or `fit_transform` on train dataset, you can use `transform()` to transform test dataset into vector.\n\n```python\ntest_vecs = fea.transform(X_test)\n```\n\nWell we have got the vector representations of train and test dataset, now we can train our model and evaluate it.\n\n```python\nfrom sklearn.svm import SVC\n\nclf=SVC(kernel='rbf', verbose=True)\nclf.fit(train_vecs, y_train)\nscore = clf.score(test_vecs, y_test)\n```\n\n# More detail\n\nYou can save the embedding model so that you can load the model next time.\n\n```python\nfea = FasttextFeature(save_file='./model.bin')\nfea.fit(X_train)\n```\n\nYou can load pretrained embedding model rather to train on train_dataset\n\n```python\nfea = FasttextFeature(pretrained_file='/path/to/pretrained_model.bin')\ntrain_vecs = fea.transform(X_train)\ntest_vecs = fea.transform(X_test)\n```\n\n# License\n\n[MIT](https://github.com/4AI/embedding_features/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4ai%2Fembedding_features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F4ai%2Fembedding_features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4ai%2Fembedding_features/lists"}