mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-13 21:26:58 +03:00
49cee4af92
* Integrate Python kernel via Binder * Add live model test for languages with examples * Update docs and code examples * Adjust margin (if not bootstrapped) * Add binder version to global config * Update terminal and executable code mixins * Pass attributes through infobox and section * Hide v-cloak * Fix example * Take out model comparison for now * Add meta text for compat * Remove chart.js dependency * Tidy up and simplify JS and port big components over to Vue * Remove chartjs example * Add Twitter icon * Add purple stylesheet option * Add utility for hand cursor (special cases only) * Add transition classes * Add small option for section * Add thumb object for small round thumbnail images * Allow unset code block language via "none" value (workaround to still allow unset language to default to DEFAULT_SYNTAX) * Pass through attributes * Add syntax highlighting definitions for Julia, R and Docker * Add website icon * Remove user survey from navigation * Don't hide GitHub icon on small screens * Make top navigation scrollable on small screens * Remove old resources page and references to it * Add Universe * Add helper functions for better page URL and title * Update site description * Increment versions * Update preview images * Update mentions of resources * Fix image * Fix social images * Fix problem with cover sizing and floats * Add divider and move badges into heading * Add docstrings * Reference converting section * Add section on converting word vectors * Move converting section to custom section and fix formatting * Remove old fastText example * Move extensions content to own section Keep weird ID to not break permalinks for now (we don't want to rewrite URLs if not absolutely necessary) * Use better component example and add factories section * Add note on larger model * Use better example for non-vector * Remove similarity in context section Only works via small models with tensors so has always been kind of confusing * Add note on init-model command * Fix lightning tour examples and make excutable if possible * Add spacy train CLI section to train * Fix formatting and add video * Fix formatting * Fix textcat example description (resolves #2246) * Add dummy file to try resolve conflict * Delete dummy file * Tidy up [ci skip] * Ensure sufficient height of loading container * Add loading animation to universe * Update Thebelab build and use better startup message * Fix asset versioning * Fix typo [ci skip] * Add note on project idea label
139 lines
6.3 KiB
JavaScript
139 lines
6.3 KiB
JavaScript
/**
|
||
* Initialise model overviews
|
||
* @param {string} repo - Repository to load from, in the format user/repo.
|
||
*/
|
||
export default function(repo) {
|
||
const LICENSES = {
|
||
'CC BY 4.0': 'https://creativecommons.org/licenses/by/4.0/',
|
||
'CC BY-SA': 'https://creativecommons.org/licenses/by-sa/3.0/',
|
||
'CC BY-SA 3.0': 'https://creativecommons.org/licenses/by-sa/3.0/',
|
||
'CC BY-SA 4.0': 'https://creativecommons.org/licenses/by-sa/4.0/',
|
||
'CC BY-NC': 'https://creativecommons.org/licenses/by-nc/3.0/',
|
||
'CC BY-NC 3.0': 'https://creativecommons.org/licenses/by-nc/3.0/',
|
||
'CC-BY-NC-SA 3.0': 'https://creativecommons.org/licenses/by-nc-sa/3.0/',
|
||
'GPL': 'https://www.gnu.org/licenses/gpl.html',
|
||
'LGPL': 'https://www.gnu.org/licenses/lgpl.html',
|
||
'MIT': 'https://opensource.org/licenses/MIT'
|
||
};
|
||
const URL = `https://raw.githubusercontent.com/${repo}/master`;
|
||
const models = [...document.querySelectorAll('[data-vue]')]
|
||
.map(el => el.getAttribute('data-vue'));
|
||
|
||
document.addEventListener('DOMContentLoaded', ev => {
|
||
fetch(`${URL}/compatibility.json`)
|
||
.then(res => res.json())
|
||
.then(json => models.forEach(modelId => new Vue({
|
||
el: `[data-vue="${modelId}"]`,
|
||
data: {
|
||
repo: `https://github.com/${repo}`,
|
||
compat: json.spacy,
|
||
loading: false,
|
||
error: false,
|
||
id: modelId,
|
||
version: 'n/a',
|
||
notes: null,
|
||
sizeFull: null,
|
||
pipeline: null,
|
||
releaseUrl: null,
|
||
description: null,
|
||
license: null,
|
||
author: null,
|
||
url: null,
|
||
vectors: null,
|
||
sources: null,
|
||
uas: null,
|
||
las: null,
|
||
tags_acc: null,
|
||
ents_f: null,
|
||
ents_p: null,
|
||
ents_r: null,
|
||
modelLicenses: LICENSES,
|
||
spacyVersion: Object.keys(json.spacy)[0]
|
||
},
|
||
computed: {
|
||
compatVersion() {
|
||
const res = this.compat[this.spacyVersion][this.id];
|
||
return res ? `${this.id}-${res[0]}` : false;
|
||
},
|
||
orderedCompat() {
|
||
return Object.keys(this.compat)
|
||
.filter(v => !v.includes('a') && !v.includes('dev') && !v.includes('rc'));
|
||
},
|
||
hasAccuracy() {
|
||
return this.uas || this.las || this.tags_acc || this.ents_f || this.ents_p || this.ents_r;
|
||
}
|
||
},
|
||
beforeMount() {
|
||
const version = this.$_getLatestVersion(this.id);
|
||
if (version) {
|
||
this.loading = true;
|
||
fetch(`${URL}/meta/${this.id}-${version}.json`)
|
||
.then(res => res.json())
|
||
.then(json => this.$_updateData(json))
|
||
.catch(err => { this.error = true });
|
||
}
|
||
},
|
||
updated() {
|
||
window.dispatchEvent(new Event('resize')); // scroll position for progress
|
||
},
|
||
methods: {
|
||
$_updateData(data) {
|
||
const fullName = `${data.lang}_${data.name}-${data.version}`;
|
||
this.version = data.version;
|
||
this.releaseUrl = `${this.repo}/releases/tag/${fullName}`;
|
||
this.sizeFull = data.size;
|
||
this.pipeline = data.pipeline;
|
||
this.notes = data.notes;
|
||
this.description = data.description;
|
||
this.vectors = this.$_formatVectors(data.vectors);
|
||
this.sources = data.sources;
|
||
this.author = data.author;
|
||
this.url = data.url;
|
||
this.license = data.license;
|
||
const accuracy = data.accuracy || {};
|
||
for (let key of Object.keys(accuracy)) {
|
||
this[key] = accuracy[key].toFixed(2);
|
||
}
|
||
this.loading = false;
|
||
},
|
||
|
||
$_getLatestVersion(modelId) {
|
||
for (let [spacy_v, models] of Object.entries(this.compat)) {
|
||
if (models[modelId]) {
|
||
return models[modelId][0];
|
||
}
|
||
}
|
||
},
|
||
|
||
$_formatVectors(data) {
|
||
if (!data) {
|
||
return 'n/a';
|
||
}
|
||
if (Object.values(data).every(n => n == 0)) {
|
||
return 'context vectors only';
|
||
}
|
||
const { keys, vectors, width } = data;
|
||
const nKeys = this.$_abbrNum(keys);
|
||
const nVectors = this.$_abbrNum(vectors);
|
||
return `${nKeys} keys, ${nVectors} unique vectors (${width} dimensions)`;
|
||
},
|
||
|
||
/**
|
||
* Abbreviate a number, e.g. 14249930 --> 14.25m.
|
||
* @param {number|string} num - The number to convert.
|
||
* @param {number} fixed - Number of decimals.
|
||
*/
|
||
$_abbrNum: function(num = 0, fixed = 1) {
|
||
const suffixes = ['', 'k', 'm', 'b', 't'];
|
||
if (num === null || num === 0) return 0;
|
||
const b = num.toPrecision(2).split('e');
|
||
const k = (b.length === 1) ? 0 : Math.floor(Math.min(b[1].slice(1), 14) / 3);
|
||
const n = (k < 1) ? num : num / Math.pow(10, k * 3);
|
||
const c = (k >= 1 && n >= 100 ) ? Math.round(n) : n.toFixed(fixed);
|
||
return (c < 0 ? c : Math.abs(c)) + suffixes[k];
|
||
}
|
||
}
|
||
})))
|
||
});
|
||
}
|