{"id":20660981,"url":"https://github.com/liatemplates/tensorflowjs","last_synced_at":"2026-05-01T02:34:22.358Z","repository":{"id":107256850,"uuid":"156857857","full_name":"LiaTemplates/TensorflowJS","owner":"LiaTemplates","description":"LiaScript template for start creating TensorFlowJS tutorials","archived":false,"fork":false,"pushed_at":"2019-05-21T09:37:48.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T17:18:15.157Z","etag":null,"topics":["javascript","liascript","liascript-template","template","tensorflow","tensorflow-tutorials"],"latest_commit_sha":null,"homepage":"https://liascript.github.io/course/?https://raw.githubusercontent.com/liaTemplates/tensorflorjs/master/README.md","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiaTemplates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-11-09T12:15:32.000Z","updated_at":"2022-02-22T11:10:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f3cb371-2502-4e0e-b168-6720b84afb9d","html_url":"https://github.com/LiaTemplates/TensorflowJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LiaTemplates/TensorflowJS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FTensorflowJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FTensorflowJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FTensorflowJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FTensorflowJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiaTemplates","download_url":"https://codeload.github.com/LiaTemplates/TensorflowJS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FTensorflowJS/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32483406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["javascript","liascript","liascript-template","template","tensorflow","tensorflow-tutorials"],"created_at":"2024-11-16T19:06:42.854Z","updated_at":"2026-05-01T02:34:22.245Z","avatar_url":"https://github.com/LiaTemplates.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nauthor:   André Dietrich\nemail:    andre.dietrich@ovgu.de\nversion:  0.0.2\nlanguage: en\nnarrator: US English Female\ncomment:  Macros for TensorFlowJS\n\nscript:   https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.3/dist/tf.min.js\n\n@onload\nwindow.reportError = function(error) {\n  let line = getLineNumber(error);\n  let details = [];\n  let msg = \"An error occured\";\n\n  if (line) {\n    details = [[{ row : line-1,\n               column : 0,\n                 text : error.message,\n                 type : \"error\" }]];\n\n    msg += \" on line \" + line;\n  }\n  return [ msg + \"\\n\" + error.message, details ];\n};\n@end\n\n@TF.eval\n\u003cscript\u003e\nasync function eee(code) {\n  let oldLog = window.console.log;\n\n  window.console.log = console.log;\n\n  try {\n    const evalString = '(async function runner() { try { ' + code + '} catch (e) { reportError(e) } })()';\n\n    await eval(evalString).catch(function(e) {\n      window.console.log = oldLog;\n      let [msg, details] = reportError(e);\n      send.lia(msg, details, false);\n      send.lia(\"LIA: stop\");\n    });\n  }\n  catch(e) {\n    window.console.log = oldLog;\n    let [msg, details] = reportError(e);\n    send.lia(msg, details, false);\n    send.lia(\"LIA: stop\");\n  }\n  send.lia(\"LIA: stop\");\n\n};\nsetTimeout(function(e){ eee(`@input`+\"\\n\") }, 10);\n\"LIA: wait\";\n\u003c/script\u003e\n@end\n\n\n@TF.eval2\n\u003cscript\u003e\nasync function eee() {\n  let file1 = `@input(0)` + \"\\n\";\n  let file2 = `@input(1)` + \"\\n\";\n  let code  = file1 + file2;\n  let oldLog = window.console.log;\n\n  window.console.log = console.log;\n\n  try {\n    const evalString = '(async function runner() { try { ' + code + '} catch (e) { reportError(e) } })()';\n\n    await eval(evalString).catch(function(e) {\n      window.console.log = oldLog;\n      let [msg, details] = reportError(e);\n      send.lia(msg, details, false);\n      send.lia(\"LIA: stop\");\n    });\n  }\n  catch(e) {\n    window.console.log = oldLog;\n    let [msg, details] = reportError(e);\n    send.lia(msg, details, false);\n    send.lia(\"LIA: stop\");\n  }\n  send.lia(\"LIA: stop\");\n};\nsetTimeout(function(e){ eee() }, 100);\n\"LIA: wait\";\n\u003c/script\u003e\n@end\n\n\n--\u003e\n\n# TensorflowJS - Template\n\nThis is a template for developing interactive machine-learning courses with\n[LiaScript](https://LiaScript.github.io) and\n[TensorFlow.js](https://js.tensorflow.org).\n\n__Try it on LiaScript:__\n\nhttps://liascript.github.io/course/?https://raw.githubusercontent.com/liaTemplates/tensorflowjs/master/README.md\n\n__See the project on Github:__\n\nhttps://github.com/liaTemplates/tensorflowjs\n\n\n                         --{{1}}--\nThere are three ways to use this template. The easiest way is to use the\n`import` statement and the url of the raw text-file of the master branch or any\nother branch or version. But you can also copy the required functionionality\ndirectly into the header of your Markdown document, see therefor the\n[last slide](#3). And of course, you could also clone this project and change\nit, as you wish.\n\n                           {{1}}\n1. Load the macros via\n\n   `import: https://raw.githubusercontent.com/liaTemplates/tensorflowjs/master/README.md`\n\n2. Copy the definitions into your Project\n\n3. Clone this repository on GitHub\n\n\n## `@TF.eval`\n\n\n                         --{{0}}--\nAdd the macro `@TF.eval` to the end of every JavaScript code-block that runs\nsome TensorFlow code and that you want to make editable in LiaScript. The given\ncode gets evaluated asynchroniously and the result is shown in a console below.\n\n\n```javascript\n// Notice there is no 'import' statement. 'tf' is available on the index-page\n// because of the script tag above.\n\n// Define a model for linear regression.\nconst model = tf.sequential();\nmodel.add(tf.layers.dense({units: 1, inputShape: [1]}));\n\n// Prepare the model for training: Specify the loss and the optimizer.\nmodel.compile({loss: 'meanSquaredError', optimizer: 'sgd'});\n\n// Generate some synthetic data for training.\nconst xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);\nconst ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);\n\n// Train the model using the data.\nmodel.fit(xs, ys, {epochs: 10}).then(() =\u003e {\n  // Use the model to do inference on a data point the model hasn't seen before:\n  // Open the browser devtools to see the output\n  model.predict(tf.tensor2d([5], [1, 1])).print();\n});\n```\n@TF.eval\n\n## Implementation\n\n                         --{{0}}--\nThe code shows how the macro `@TF.eval` is implemented. The script command at\nthe top loads the TensorFlowJS javascript library and onload is used to define\nfunction reportError at the initialization phase.\n\n``` html\nscript:   https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.3/dist/tf.min.js\n\n@onload\nwindow.reportError = function(error) {\n  let line = getLineNumber(error);\n  let details = [];\n  let msg = \"An error occured\";\n\n  if (line) {\n    details = [[{ row : line-1,\n               column : 0,\n                 text : error.message,\n                 type : \"error\" }]];\n\n    msg += \" on line \" + line;\n  }\n  return [ msg + \"\\n\" + error.message, details ];\n};\n@end\n\n@TF.eval\n\u003cscript\u003e\nasync function eee(code) {\n  let oldLog = window.console.log;\n\n  window.console.log = console.log;\n\n  try {\n    const evalString = '(async function runner() { try { ' + code + '} catch (e) { reportError(e) } })()';\n\n    await eval(evalString).catch(function(e) {\n      window.console.log = oldLog;\n      let [msg, details] = reportError(e);\n      send.lia(msg, details, false);\n      send.lia(\"LIA: stop\");\n    });\n  }\n  catch(e) {\n    window.console.log = oldLog;\n    let [msg, details] = reportError(e);\n    send.lia(msg, details, false);\n    send.lia(\"LIA: stop\");\n  }\n  send.lia(\"LIA: stop\");\n\n};\nsetTimeout(function(e){ eee(`@input`+\"\\n\") }, 10);\n\"LIA: wait\";\n\u003c/script\u003e\n@end\n```\n\n                         --{{1}}--\nIf you want to minimize loading effort in your LiaScript project, you can also\ncopy this code and paste it into your main comment header, see the code in the\nraw file of this document.\n\n                           {{1}}\nhttps://raw.githubusercontent.com/liaTemplates/tensorflowjs/master/README.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliatemplates%2Ftensorflowjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliatemplates%2Ftensorflowjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliatemplates%2Ftensorflowjs/lists"}