Update README.md
Browse files
README.md
CHANGED
|
@@ -6,4 +6,31 @@ pipeline_tag: time-series-forecasting
|
|
| 6 |
|
| 7 |
https://huggingface.co/ibm-granite/granite-timeseries-patchtsmixer with ONNX weights to be compatible with Transformers.js.
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|
|
|
|
| 6 |
|
| 7 |
https://huggingface.co/ibm-granite/granite-timeseries-patchtsmixer with ONNX weights to be compatible with Transformers.js.
|
| 8 |
|
| 9 |
+
## Usage (Transformers.js)
|
| 10 |
+
|
| 11 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
|
| 12 |
+
```bash
|
| 13 |
+
npm i @huggingface/transformers
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
**Example:** Time series forecasting w/ `onnx-community/granite-timeseries-patchtsmixer`
|
| 17 |
+
|
| 18 |
+
```js
|
| 19 |
+
import { PatchTSMixerForPrediction, Tensor } from '@huggingface/transformers';
|
| 20 |
+
|
| 21 |
+
const model_id = "onnx-community/granite-timeseries-patchtsmixer";
|
| 22 |
+
const model = await PatchTSMixerForPrediction.from_pretrained(model_id, { dtype: "fp32" });
|
| 23 |
+
|
| 24 |
+
const dims = [64, 512, 7];
|
| 25 |
+
const prod = dims.reduce((a, b) => a * b, 1);
|
| 26 |
+
const past_values = new Tensor('float32',
|
| 27 |
+
Float32Array.from({ length: prod }, (_, i) => i / prod),
|
| 28 |
+
dims,
|
| 29 |
+
);
|
| 30 |
+
const { prediction_outputs } = await model({ past_values });
|
| 31 |
+
console.log(prediction_outputs);
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|