Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private trainTestAndSaveModels = async () => {
const files = [
withPrefix('/models/dictionary.json'),
withPrefix('/models/ngram_to_id_dictionary.json'),
withPrefix('/models/dataset_params.json'),
withPrefix('/models/dataset_training.json'),
withPrefix('/models/dataset_testing.json')
];
const jsonFiles = await this.downloadFiles(files);
const pretrainedNGramVectors = new Map(jsonFiles[0].data);
const ngramToIdDictionary = jsonFiles[1].data;
const datasetParams = jsonFiles[2].data;
const datasetTraining = jsonFiles[3].data;
const datasetTest = jsonFiles[4].data;
await this.timeoutInMs(200); // give some time for the state update after the model setup (before the gpu blocks)
this.setState({
datasetParams,
datasetTest,
datasetTraining,
embeddingsAndTrainingDatasetLoaded: true,
ngramToIdDictionary,
pretrainedNGramVectors
});
private trainTestAndSaveModels = async () => {
const files = [
withPrefix('/models/dictionary.json'),
withPrefix('/models/ngram_to_id_dictionary.json'),
withPrefix('/models/dataset_params.json'),
withPrefix('/models/dataset_training.json'),
withPrefix('/models/dataset_testing.json')
];
const jsonFiles = await this.downloadFiles(files);
const pretrainedNGramVectors = new Map(jsonFiles[0].data);
const ngramToIdDictionary = jsonFiles[1].data;
const datasetParams = jsonFiles[2].data;
const datasetTraining = jsonFiles[3].data;
const datasetTest = jsonFiles[4].data;
await this.timeoutInMs(200); // give some time for the state update after the model setup (before the gpu blocks)
this.setState({
datasetParams,
datasetTest,
datasetTraining,
embeddingsAndTrainingDatasetLoaded: true,
ngramToIdDictionary,
pretrainedNGramVectors
import PropTypes from 'prop-types';
import { withPrefix } from 'gatsby-link';
// This is a gatsby limitation will be fixed in newer version
let globalStyles = require(`!raw-loader!@patternfly/react-core/../dist/styles/base.css`);
globalStyles = globalStyles.replace(/\.\/assets\//g, withPrefix('/assets/'));
const localStyles = require(`!raw-loader!./index.css`);
import { injectGlobal } from 'emotion';
injectGlobal(globalStyles);
injectGlobal(localStyles);
const propTypes = {
children: PropTypes.func.isRequired
};
const Layout = ({ children }) => children();
Layout.propTypes = propTypes;
export default Layout;
onClick={() => {
navigateTo(withPrefix(item.url));
toggleDrawer(false);
}}
>
const formatStorybookUrl = ({componentName, componentStory}) => withPrefix(
url.format({
pathname: '/storybook/index.html',
query: {
selectedKind: componentName,
selectedStory: componentStory,
},
})
);
const ListLinkOut = props => (
<a> props.onClick()}
href={props.to}
rel="noopener noreferrer"
target="_blank"
>
<p>{props.children}</p>
</a>
);
private downloadsTrainedModel = async (backend: 'web' | 'node' | 'keras') => {
const modelsUrls = {
keras: {
classification: withPrefix('/models/pretrained/keras/classification/model.json'),
embedding: withPrefix('/models/pretrained/keras/embedding/model.json'),
ner: withPrefix('/models/pretrained/keras/ner/model.json')
},
node: {
classification: withPrefix('/models/pretrained/node/classification/model.json'),
embedding: withPrefix('/models/pretrained/node/embedding/model.json'),
ner: withPrefix('/models/pretrained/node/ner/model.json')
},
web: {
classification: withPrefix('/models/pretrained/web/classification/classification.json'),
embedding: withPrefix('/models/pretrained/web/embedding/embedding.json'),
ner: withPrefix('/models/pretrained/web/ner/ner.json')
}
};
const pretrainedEmbedding = await tf.loadLayersModel(modelsUrls[backend].embedding, { strict: false });
const pretrainedClassifier = await tf.loadLayersModel(modelsUrls[backend].classification);
const pretrainedNer = await tf.loadLayersModel(modelsUrls[backend].ner);
return { pretrainedEmbedding, pretrainedClassifier, pretrainedNer };
};
private downloadsTrainedModel = async (backend: 'web' | 'node' | 'keras') => {
const modelsUrls = {
keras: {
classification: withPrefix('/models/pretrained/keras/classification/model.json'),
embedding: withPrefix('/models/pretrained/keras/embedding/model.json'),
ner: withPrefix('/models/pretrained/keras/ner/model.json')
},
node: {
classification: withPrefix('/models/pretrained/node/classification/model.json'),
embedding: withPrefix('/models/pretrained/node/embedding/model.json'),
ner: withPrefix('/models/pretrained/node/ner/model.json')
},
web: {
classification: withPrefix('/models/pretrained/web/classification/classification.json'),
embedding: withPrefix('/models/pretrained/web/embedding/embedding.json'),
ner: withPrefix('/models/pretrained/web/ner/ner.json')
}
};
const pretrainedEmbedding = await tf.loadLayersModel(modelsUrls[backend].embedding, { strict: false });
const pretrainedClassifier = await tf.loadLayersModel(modelsUrls[backend].classification);
const pretrainedNer = await tf.loadLayersModel(modelsUrls[backend].ner);
return { pretrainedEmbedding, pretrainedClassifier, pretrainedNer };
};
const ListLinkOut = props => (
<li style="{{">
<a href="{props.to}" rel="noopener noreferrer">
{props.children}
</a>
</li>
);
private downloadsTrainedModel = async (backend: 'web' | 'node' | 'keras') => {
const modelsUrls = {
keras: {
classification: withPrefix('/models/pretrained/keras/classification/model.json'),
embedding: withPrefix('/models/pretrained/keras/embedding/model.json'),
ner: withPrefix('/models/pretrained/keras/ner/model.json')
},
node: {
classification: withPrefix('/models/pretrained/node/classification/model.json'),
embedding: withPrefix('/models/pretrained/node/embedding/model.json'),
ner: withPrefix('/models/pretrained/node/ner/model.json')
},
web: {
classification: withPrefix('/models/pretrained/web/classification/classification.json'),
embedding: withPrefix('/models/pretrained/web/embedding/embedding.json'),
ner: withPrefix('/models/pretrained/web/ner/ner.json')
}
};
const pretrainedEmbedding = await tf.loadLayersModel(modelsUrls[backend].embedding, { strict: false });
const pretrainedClassifier = await tf.loadLayersModel(modelsUrls[backend].classification);
const pretrainedNer = await tf.loadLayersModel(modelsUrls[backend].ner);