|
| 1 | +<!-- |
| 2 | +Copyright 2018 Google LLC. All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +============================================================================== |
| 16 | +--> |
| 17 | + |
| 18 | +<!doctype html> |
| 19 | + |
| 20 | +<head> |
| 21 | + <meta charset="UTF-8"> |
| 22 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 23 | + <link rel="stylesheet" href="../shared/tfjs-examples.css" /> |
| 24 | + <title>TensorFlow.js: Date Conversion Through Attention</title> |
| 25 | +</head> |
| 26 | +<style> |
| 27 | + .horizontal-sections { |
| 28 | + display: inline-block; |
| 29 | + vertical-align: top; |
| 30 | + } |
| 31 | + .date-label { |
| 32 | + font-size: 18px; |
| 33 | + font-family: monospace; |
| 34 | + padding: 5px; |
| 35 | + width: 300px; |
| 36 | + display: block; |
| 37 | + } |
| 38 | + .hint { |
| 39 | + font-size: 12px; |
| 40 | + font-family: monospace; |
| 41 | + } |
| 42 | + .dates { |
| 43 | + font-size: 24px; |
| 44 | + font-family: monospace; |
| 45 | + } |
| 46 | + .date-input-output-section { |
| 47 | + display: inline-block; |
| 48 | + } |
| 49 | + .attention-section { |
| 50 | + margin-top: 8px; |
| 51 | + } |
| 52 | + #attention-heatmap { |
| 53 | + width: 600px; |
| 54 | + height: 360px; |
| 55 | + border: 2px solid lightblue |
| 56 | + } |
| 57 | + #date-format-table { |
| 58 | + font-size: 15px; |
| 59 | + font-family: monospace; |
| 60 | + text-align: left; |
| 61 | + } |
| 62 | + li { |
| 63 | + padding-top: 1px; |
| 64 | + padding-bottom: 2px; |
| 65 | + text-decoration: underline; |
| 66 | + color: blue; |
| 67 | + } |
| 68 | + #random-date { |
| 69 | + margin-top: 10px; |
| 70 | + padding-top: 5px; |
| 71 | + padding-bottom: 5px; |
| 72 | + } |
| 73 | + .benchmark { |
| 74 | + color: gray; |
| 75 | + } |
| 76 | +</style> |
| 77 | + |
| 78 | +<body> |
| 79 | + <div class='tfjs-example-container centered-container'> |
| 80 | + <section class='title-area'> |
| 81 | + <h1>TensorFlow.js: Date String Conversion</h1> |
| 82 | + <p class='subtitle'>Solving a Sequence-to-Sequence Task Using LSTM and Attention</p> |
| 83 | + </section> |
| 84 | + <section> |
| 85 | + <p class='section-head'>Description</p> |
| 86 | + <p> |
| 87 | + This example demonstrates the inference stage of using a sequence-to-sequence |
| 88 | + model to convert a myriad of common date formats into the |
| 89 | + <a href="https://en.wikipedia.org/wiki/ISO_8601#Calendar_dates" target="_blank"> |
| 90 | + ISO 8601 date format |
| 91 | + </a> |
| 92 | + (i.e., YYYY-MM-DD). The list below shows examples of the supported input date |
| 93 | + formats. |
| 94 | + </p> |
| 95 | + |
| 96 | + <p> |
| 97 | + The model is based on |
| 98 | + <a href="https://js.tensorflow.org/api/latest/#layers.lstm" target="_blank">LSTM</a> |
| 99 | + and the |
| 100 | + <a href="https://medium.com/syncedreview/a-brief-overview-of-attention-mechanism-13c578ba9129" target="_blank"> |
| 101 | + attention mechanism |
| 102 | + </a>. |
| 103 | + </p> |
| 104 | + |
| 105 | + <p> |
| 106 | + The training uses |
| 107 | + <a href="https://github.com/tensorflow/tfjs-node">tfjs-node</a> |
| 108 | + and runs in the backend Node.js environment. The training script |
| 109 | + can be found |
| 110 | + <a href="https://github.com/tensorflow/tfjs-examples/tree/master/date-conversion-attention/train.js"> |
| 111 | + here |
| 112 | + </a>. |
| 113 | + </p> |
| 114 | + </section> |
| 115 | + <section> |
| 116 | + <p class='section-head'>Status</p> |
| 117 | + <p> |
| 118 | + <span id="status"></span> |
| 119 | + </p> |
| 120 | + </section> |
| 121 | + <section> |
| 122 | + <p class='section-head'>Support Date Formats</p> |
| 123 | + <p> |
| 124 | + <div id="date-format-table"> |
| 125 | + <div>Examples for supported formats (click to try):</div> |
| 126 | + <ul> |
| 127 | + <li><span class="input-date-example">23Jan2015</span></li> |
| 128 | + <li><span class="input-date-example">012315</span></li> |
| 129 | + <li><span class="input-date-example">01/23/15</span></li> |
| 130 | + <li><span class="input-date-example">1/23/15</span></li> |
| 131 | + <li><span class="input-date-example">01/23/2015</span></li> |
| 132 | + <li><span class="input-date-example">1/23/2015</span></li> |
| 133 | + <li><span class="input-date-example">23-01-2015</span></li> |
| 134 | + <li><span class="input-date-example">23-1-2015</span></li> |
| 135 | + <li><span class="input-date-example">JAN 23, 15</span></li> |
| 136 | + <li><span class="input-date-example">Jan 23, 2015</span></li> |
| 137 | + <li><span class="input-date-example">23.01.2015</span></li> |
| 138 | + <li><span class="input-date-example">23.1.2015</span></li> |
| 139 | + <li><span class="input-date-example">2015.01.23</span></li> |
| 140 | + <li><span class="input-date-example">2015.1.23</span></li> |
| 141 | + <li><span class="input-date-example">20150123</span></li> |
| 142 | + <li><span class="input-date-example">2015/01/23</span></li> |
| 143 | + <li><span class="input-date-example">2015-01-23</span></li> |
| 144 | + <li><span class="input-date-example">2015-1-23</span></li> |
| 145 | + </ul> |
| 146 | + </table> |
| 147 | + </p> |
| 148 | + </section> |
| 149 | + |
| 150 | + <div class="horizontal-sections"> |
| 151 | + <div class="horizontal-sections"> |
| 152 | + <div class="date-input-output-section"> |
| 153 | + <div class="date-label">Input date string:</div> |
| 154 | + <input type="text" class="dates" id="input-date-string" value="JAN 20, 2001"></input> |
| 155 | + </div> |
| 156 | + |
| 157 | + <div class="hint">Press Enter to Refresh Conversion</div> |
| 158 | + <button id="random-date">Random</button> |
| 159 | + </div> |
| 160 | + |
| 161 | + <div class="horizontal-sections"> |
| 162 | + <div class="date-input-output-section"> |
| 163 | + <div class="date-label">Output date string:</div> |
| 164 | + <input type="text" class="dates" id="output-date-string" disabled="true"></input> |
| 165 | + </div> |
| 166 | + |
| 167 | + <div class="attention-section"> |
| 168 | + <div class="date-label">Attention matrix:</div> |
| 169 | + <div id="attention-heatmap"></div> |
| 170 | + </div> |
| 171 | + </div> |
| 172 | + </div> |
| 173 | + </div> |
| 174 | + |
| 175 | +</body> |
| 176 | + |
| 177 | +<script src="index.js"></script> |
0 commit comments