ilar06 commited on
Commit
71849a9
ยท
verified ยท
1 Parent(s): b1a3190

Update sentiments.html

Browse files
Files changed (1) hide show
  1. sentiments.html +7 -30
sentiments.html CHANGED
@@ -6,12 +6,8 @@
6
  <title>Sentiment Analysis - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
9
-
10
- import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
11
-
12
- // To-Do: transfomers.js ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ค‘ pipeline ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ import ๊ตฌ๋ฌธ์„ ์™„์„ฑํ•˜์‹ญ์‹œ์˜ค.
13
- // ํžŒํŠธ: import {}
14
-
15
  // Make it available globally
16
  window.pipeline = pipeline;
17
  </script>
@@ -108,50 +104,31 @@
108
  </div>
109
  </div>
110
 
111
- <script>
112
-
113
  let sentimentAnalysis;
114
  let reviewer;
115
  let toxic_classifier;
116
-
117
  // Initialize the sentiment analysis model
118
  async function initializeModel() {
119
- // pipeline ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์„ฑ๋ถ„์„์— ์‚ฌ์šฉํ•  Xenova/distilbert-base-uncased-finetuned-sst-2-english ๋ชจ๋ธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ sentimentAnalysis์— ์ €์žฅํ•˜์‹ญ์‹œ์˜ค
120
- // ํžŒํŠธ: sentimentAnalysis = await pipeline
121
- sentimentAnalysis = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');
122
- toxic_classifier = await pipeline('text-classification', 'Xenova/toxic-bert');
123
  }
124
-
125
  async function analyzeSentiment() {
126
  const textFieldValue = document.getElementById("sentimentText").value.trim();
127
-
128
  const result = await sentimentAnalysis(textFieldValue);
129
-
130
  document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
131
  }
132
-
133
  async function analyzeSentimentMulti() {
134
- const textFieldValue1 = document.getElementById("sentimentText1sentimentText").value.trim();
135
  const textFieldValue2 = document.getElementById("sentimentText2").value.trim();
136
- // ์œ„์—์„œ ์ƒ์„ฑํ•œ ๊ฐ์„ฑ๋ถ„์„ ๋ชจ๋ธ ๊ฐ์ฒด์— sentimentText1๊ณผ sentimentText2๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๊ฐ์ƒ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๊ทธ ๊ฒฐ๊ณผ๋ฅผ result์— ์ €์ •ํ•˜์‹ญ์‹œ์˜ค.
137
- // ํžŒํŠธ : cont result =
138
-
139
- const result = await sentimentAnalysis([textFieldValue1, textFieldValue2]);
140
-
141
  document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
142
  }
143
-
144
-
145
  async function toxicReview() {
146
-
147
  const textFieldValue = document.getElementById("toxicText").value.trim();
148
-
149
  const result = await toxic_classifier(textFieldValue, { topk: null });
150
-
151
  document.getElementById("toxicOutputArea").innerText = JSON.stringify(result, null, 2);
152
-
153
  }
154
-
155
  // Initialize the model after the DOM is completely loaded
156
  window.addEventListener("DOMContentLoaded", initializeModel);
157
  </script>
 
6
  <title>Sentiment Analysis - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
9
+ // Import the library
10
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
 
 
 
 
11
  // Make it available globally
12
  window.pipeline = pipeline;
13
  </script>
 
104
  </div>
105
  </div>
106
 
107
+ <script>
 
108
  let sentimentAnalysis;
109
  let reviewer;
110
  let toxic_classifier;
 
111
  // Initialize the sentiment analysis model
112
  async function initializeModel() {
113
+ sentimentAnalysis = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');
114
+ toxic_classifier = await pipeline('text-classification', 'Xenova/toxic-bert');
 
 
115
  }
 
116
  async function analyzeSentiment() {
117
  const textFieldValue = document.getElementById("sentimentText").value.trim();
 
118
  const result = await sentimentAnalysis(textFieldValue);
 
119
  document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
120
  }
 
121
  async function analyzeSentimentMulti() {
122
+ const textFieldValue1 = document.getElementById("sentimentText1").value.trim();
123
  const textFieldValue2 = document.getElementById("sentimentText2").value.trim();
124
+ const result = await sentimentAnalysis([textFieldValue1, textFieldValue2]);
 
 
 
 
125
  document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
126
  }
 
 
127
  async function toxicReview() {
 
128
  const textFieldValue = document.getElementById("toxicText").value.trim();
 
129
  const result = await toxic_classifier(textFieldValue, { topk: null });
 
130
  document.getElementById("toxicOutputArea").innerText = JSON.stringify(result, null, 2);
 
131
  }
 
132
  // Initialize the model after the DOM is completely loaded
133
  window.addEventListener("DOMContentLoaded", initializeModel);
134
  </script>