Kalemat / feature.js
Omartificial-Intelligence-Space's picture
create function.js
15f62f3 verified
raw
history blame contribute delete
610 Bytes
function create_token_frequency_chart(tokenized_text) {
// Count token frequencies
const token_counts = {};
for (const token of tokenized_text) {
token_counts[token] = (token_counts[token] || 0) + 1;
}
// Create Plotly chart data
const data = [
{
x: Object.keys(token_counts),
y: Object.values(token_counts),
type: 'bar',
},
];
// Create chart layout
const layout = {
title: 'Token Frequency',
xaxis: { title: 'Tokens' },
yaxis: { title: 'Frequency' },
};
// Generate and return chart HTML
return Plotly.newPlot('chart-div', data, layout);
}