Spaces:
Running
Running
Update zero-shot-classification.html
Browse files
zero-shot-classification.html
CHANGED
|
@@ -6,9 +6,8 @@
|
|
| 6 |
<title>Zero Shot Classification - Hugging Face Transformers.js</title>
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
-
//
|
| 10 |
-
|
| 11 |
-
|
| 12 |
// Make it available globally
|
| 13 |
window.pipeline = pipeline;
|
| 14 |
</script>
|
|
@@ -91,37 +90,25 @@
|
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<script>
|
| 94 |
-
|
| 95 |
let classifier;
|
| 96 |
let classifierMulti;
|
| 97 |
-
|
| 98 |
// Initialize the sentiment analysis model
|
| 99 |
async function initializeModel() {
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
// To-Do: pipeline 함수에 task와 model을 지정하여 zero 샷 분류 모델을 생성하여 classifierMulti에 저장하십시오. 모델은 Xenova/nli-deberta-v3-xsmall 사용
|
| 103 |
-
|
| 104 |
-
|
| 105 |
}
|
| 106 |
-
|
| 107 |
async function classifyText() {
|
| 108 |
const text = document.getElementById("textText").value.trim();
|
| 109 |
const labels = document.getElementById("labelsText").value.trim().split(",").map(item => item.trim());
|
| 110 |
-
|
| 111 |
const result = await classifier(text, labels);
|
| 112 |
-
|
| 113 |
document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
|
| 114 |
}
|
| 115 |
-
|
| 116 |
async function classifyTextMulti() {
|
| 117 |
const text = document.getElementById("textTextMulti").value.trim();
|
| 118 |
const labels = document.getElementById("labelsTextMulti").value.trim().split(",").map(item => item.trim());
|
| 119 |
-
|
| 120 |
const result = await classifierMulti(text, labels, { multi_label: true });
|
| 121 |
-
|
| 122 |
document.getElementById("outputAreaMulti").innerText = JSON.stringify(result, null, 2);
|
| 123 |
}
|
| 124 |
-
|
| 125 |
// Initialize the model after the DOM is completely loaded
|
| 126 |
window.addEventListener("DOMContentLoaded", initializeModel);
|
| 127 |
</script>
|
|
|
|
| 6 |
<title>Zero Shot Classification - Hugging Face Transformers.js</title>
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
+
// Import the library
|
| 10 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.4';
|
|
|
|
| 11 |
// Make it available globally
|
| 12 |
window.pipeline = pipeline;
|
| 13 |
</script>
|
|
|
|
| 90 |
</div>
|
| 91 |
|
| 92 |
<script>
|
|
|
|
| 93 |
let classifier;
|
| 94 |
let classifierMulti;
|
|
|
|
| 95 |
// Initialize the sentiment analysis model
|
| 96 |
async function initializeModel() {
|
| 97 |
+
classifier = await pipeline('zero-shot-classification', 'Xenova/mobilebert-uncased-mnli');
|
| 98 |
+
classifierMulti = await pipeline('zero-shot-classification', 'Xenova/nli-deberta-v3-xsmall');
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
|
|
|
| 100 |
async function classifyText() {
|
| 101 |
const text = document.getElementById("textText").value.trim();
|
| 102 |
const labels = document.getElementById("labelsText").value.trim().split(",").map(item => item.trim());
|
|
|
|
| 103 |
const result = await classifier(text, labels);
|
|
|
|
| 104 |
document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
|
| 105 |
}
|
|
|
|
| 106 |
async function classifyTextMulti() {
|
| 107 |
const text = document.getElementById("textTextMulti").value.trim();
|
| 108 |
const labels = document.getElementById("labelsTextMulti").value.trim().split(",").map(item => item.trim());
|
|
|
|
| 109 |
const result = await classifierMulti(text, labels, { multi_label: true });
|
|
|
|
| 110 |
document.getElementById("outputAreaMulti").innerText = JSON.stringify(result, null, 2);
|
| 111 |
}
|
|
|
|
| 112 |
// Initialize the model after the DOM is completely loaded
|
| 113 |
window.addEventListener("DOMContentLoaded", initializeModel);
|
| 114 |
</script>
|