summaryrefslogtreecommitdiffstats
path: root/toolkit/components/ml/docs/index.rst
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
commita90a5cba08fdf6c0ceb95101c275108a152a3aed (patch)
tree532507288f3defd7f4dcf1af49698bcb76034855 /toolkit/components/ml/docs/index.rst
parentAdding debian version 126.0.1-1. (diff)
downloadfirefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz
firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/ml/docs/index.rst')
-rw-r--r--toolkit/components/ml/docs/index.rst47
1 files changed, 47 insertions, 0 deletions
diff --git a/toolkit/components/ml/docs/index.rst b/toolkit/components/ml/docs/index.rst
new file mode 100644
index 0000000000..a171a982a3
--- /dev/null
+++ b/toolkit/components/ml/docs/index.rst
@@ -0,0 +1,47 @@
+Machine Learning
+================
+
+This component is an experimental machine learning local inference engine based on
+Transformers.js and the ONNX runtime.
+
+In the example below, an image is converted to text using the `image-to-text` task.
+
+
+.. code-block:: javascript
+
+ const {PipelineOptions, EngineProcess } = ChromeUtils.importESModule("chrome://global/content/ml/EngineProcess.sys.mjs");
+
+ // First we create a pipeline options object, which contains the task name
+ // and any other options needed for the task
+ const options = new PipelineOptions({taskName: "image-to-text" });
+
+ // Next, we create an engine parent object via EngineProcess
+ const engineParent = await EngineProcess.getMLEngineParent();
+
+ // We then create the engine object, using the options
+ const engine = engineParent.getEngine(options);
+
+ // At this point we are ready to do some inference.
+
+ // We need to get the image as an array buffer and wrap it into a request object
+ const response = await fetch("https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg");
+ const buffer = await response.arrayBuffer();
+ const mimeType = response.headers.get('Content-Type');
+ const request = {
+ data: buffer,
+ mimeType: mimeType
+ };
+
+ // Finally, we run the engine with the request object
+ const res = await engine.run(request);
+
+ // The result is a string containing the text extracted from the image
+ console.log(res);
+
+
+Supported Inference Tasks
+:::::::::::::::::::::::::
+
+The following tasks are supported by the machine learning engine:
+
+.. js:autofunction:: imageToText