machine-learning libraries for Source Academy
The primary objective of this project is to create a reimplementation of PyTorch in TypeScript, with an educational focus. This project is developed with Source Academy integration in mind.
This project reimplements core parts of PyTorch while trying to keep the codebase simple, and the API as close to PyTorch as possible.
Using Pyodide, we can run Python code in the browser. Using pyodide_bridge.py in a way similar to examples/pyodide/ we can run PyTorch-like code in the browser.
events in src/util.ts. It is similar to hooks in PyTorch.number for all tensor elements.Install yarn:
corepack enable
# or
npm install -g yarn
Install dependencies:
yarn install
First, build it:
yarn build
See examples/ for examples.
See examples/basic_backpropagation.js.
node examples/basic_backpropagation.js
You can run http-server and load examples/browser/index.html to see how it works.
yarn serve
# and navigate to http://localhost:8080/examples/browser/index.html to run torch in js
# or http://localhost:8080/examples/pyodide/index.html to run in python
# or http://localhost:8080/test/ to run the tests
Contributions are welcome. The short version:
yarn test to verify everything passes.For full details on the codebase, how to add operations, and the testing setup, see CONTRIBUTING.md.