Skip to content

Commit 482226b

Browse files
authored
[sentiment] Revise *_CHAR to *_INDEX for clarity (#233)
1 parent 66d9f35 commit 482226b

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ to another project.
9898
</tr>
9999
<tr>
100100
<td><a href="./date-conversion-attention">date-conversion-attention</a></td>
101-
<td></td>
102-
<td></td>
103-
<td>Attention RNN for text-to-text conversion</td>
104-
<td></td>
105-
<td></td>
106-
<td></td>
107-
<td></td>
108-
<td></td>
101+
<td><a href="https://storage.googleapis.com/tfjs-examples/date-conversion-attention/dist/index.html">🔗</a></td>
102+
<td>Text</td>
103+
<td>Text-to-text conversion</td>
104+
<td>Attention mechanism, RNN</td>
105+
<td>Node</td>
106+
<td>Browser and Node</td>
107+
<td>Layers</td>
108+
<td>Saving to filesystem and loading in browser</td>
109109
</tr>
110110
<tr>
111111
<td><a href="./iris">iris</a></td>
@@ -144,7 +144,7 @@ to another project.
144144
<td><a href="./lstm-text-generation">lstm-text-generation</a></td>
145145
<td><a href="https://storage.googleapis.com/tfjs-examples/lstm-text-generation/dist/index.html">🔗</a></td>
146146
<td>Text</td>
147-
<td>Sequence-to-prediction</td>
147+
<td>Sequence prediction</td>
148148
<td>RNN: LSTM</td>
149149
<td>Browser</td>
150150
<td>Browser</td>

sentiment/data.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import * as https from 'https';
2121
import * as os from 'os';
2222
import * as path from 'path';
2323

24-
import {OOV_CHAR, PAD_CHAR, padSequences} from './sequence_utils';
24+
import {OOV_INDEX, PAD_INDEX, padSequences} from './sequence_utils';
2525

2626
// `import` doesn't seem to work with extract-zip.
2727
const extract = require('extract-zip');
@@ -36,7 +36,7 @@ const METADATA_TEMPLATE_URL =
3636
*
3737
* @param {string} filePath Data file on local filesystem.
3838
* @param {string} numWords Number of words in the vocabulary. Word indices
39-
* that exceed this limit will be marked as `OOV_CHAR`.
39+
* that exceed this limit will be marked as `OOV_INDEX`.
4040
* @param {string} maxLen Length of each sequence. Longer sequences will be
4141
* pre-truncated; shorter ones will be pre-padded.
4242
* @return {tf.Tensor} The dataset represented as a 2D `tf.Tensor` of shape
@@ -60,7 +60,7 @@ function loadFeatures(filePath, numWords, maxLen) {
6060
seq = [];
6161
} else {
6262
// Sequence continues.
63-
seq.push(value >= numWords ? OOV_CHAR : value);
63+
seq.push(value >= numWords ? OOV_INDEX : value);
6464
}
6565
index += 4;
6666
}

sentiment/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import * as tf from '@tensorflow/tfjs';
1919
import * as loader from './loader';
2020
import * as ui from './ui';
21-
import {OOV_CHAR, padSequences} from './sequence_utils';
21+
import {OOV_INDEX, padSequences} from './sequence_utils';
2222

2323
const HOSTED_URLS = {
2424
model:
@@ -65,7 +65,7 @@ class SentimentPredictor {
6565
const sequence = inputText.map(word => {
6666
let wordIndex = this.wordIndex[word] + this.indexFrom;
6767
if (wordIndex > this.vocabularySize) {
68-
wordIndex = OOV_CHAR;
68+
wordIndex = OOV_INDEX;
6969
}
7070
return wordIndex;
7171
});

sentiment/sequence_utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* Utilities for sequential data.
2020
*/
2121

22-
export const PAD_CHAR = 0;
23-
export const OOV_CHAR = 2;
22+
export const PAD_INDEX = 0; // Index of the padding character.
23+
export const OOV_INDEX = 2; // Index fo the OOV character.
2424

2525
/**
2626
* Pad and truncate all sequences to the same length
@@ -34,7 +34,7 @@ export const OOV_CHAR = 2;
3434
* @param {number} value Padding value.
3535
*/
3636
export function padSequences(
37-
sequences, maxLen, padding = 'pre', truncating = 'pre', value = PAD_CHAR) {
37+
sequences, maxLen, padding = 'pre', truncating = 'pre', value = PAD_INDEX) {
3838
// TODO(cais): This perhaps should be refined and moved into tfjs-preproc.
3939
return sequences.map(seq => {
4040
// Perform truncation.

0 commit comments

Comments
 (0)