Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arjunsk/movector
https://github.com/arjunsk/movector
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/arjunsk/movector
- Owner: arjunsk
- Created: 2023-08-01T15:49:44.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-01-19T04:36:25.000Z (12 months ago)
- Last Synced: 2024-10-16T08:12:09.857Z (3 months ago)
- Language: Python
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### MO Vector Python Client
Work in progress.
### Sample code:
```python
import implicit
from implicit.datasets.movielens import get_movielensfrom sqlalchemy import create_engine, insert, select, text, Integer, String
from sqlalchemy.orm import declarative_base, mapped_column, Sessionfrom movector.sqlalchemy import VectorF32
engine = create_engine("mysql+pymysql://root:[email protected]:6001/a")
with engine.connect() as conn:
results = conn.execute(text("SELECT 42;"))Base = declarative_base()
class User(Base):
__tablename__ = 'user'id = mapped_column(Integer, primary_key=True)
factors = mapped_column(VectorF32(20))Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)titles, ratings = get_movielens('100k')
model = implicit.als.AlternatingLeastSquares(factors=20)
model.fit(ratings)users = [dict(factors=factors) for i, factors in enumerate(model.user_factors)]
session = Session(engine)
session.execute(insert(User), users)user = session.get(User, 70)
print('user-based recs:', [user.id, user.factors])# Prints:
# user-based recs: [70, array([ 7.8333974 , 8.490529 , 8.774695 , 9.268776 , 6.0036736 ,
# 6.134292 , 0.19642895, 7.596437 , 2.9758034 , 7.9472003 ,
# 4.068931 , 0.58703905, 1.5298995 , 5.9633737 , 2.553488 ,
# 4.9483128 , 10.799758 , 0.6393655 , 7.034949 , 6.145868 ],
# dtype=float32)]
```Async Support: https://github.com/sqlalchemy/sqlalchemy/blob/main/examples/asyncio/basic.py
Derived From: https://github.com/pgvector/pgvector-python/blob/master/pgvector/sqlalchemy/__init__.py