This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly | |
import plotly.graph_objects as go | |
x = pd.Series({0:2020, 1:2021, 2:2022}) | |
y = pd.Series({0: 10, 1:20, 2:30}) | |
fig = go.Figure() | |
fig.add_trace(go.Bar(x = x, y = y)) | |
fig.update_traces( | |
marker_color='rgb(68, 84, 106)', | |
marker_line_width=0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
============================================================ | |
Plotly.js barchart | |
============================================================ | |
--> | |
<div class="row"> | |
<div class="col-lg-4" style="outline:1px solid black;"> | |
<strong>Day-ahead prices</strong> | |
<div id="chart" class="container col-12"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Profiler | |
# cumulative time -- time in function + calls to other functions | |
# total time -- time only in function without calls to other funs | |
import cProfile | |
import pstats | |
import io | |
def print_c_profiler(pr, lines_to_print=25): | |
""" | |
Create the speed profile of the arbitrary code. | |
Example usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Initiate pipeline for Text summarization | |
summarizer = pipeline("summarization", model="t5-base") | |
# 2. Input sentence in Estonian | |
sentence_est = r""" | |
E-Lab on Eesti Energia IT osakonda kuuluv uurimis- ja arendusüksus. | |
Üksuse eesmärk on kiirendada innovatsiooni ja aidata kaasa uute ideede | |
esimeste arendusetappide (kontseptsiooni tõestus ja prototüüpimine) läbimisele. | |
Tiimis on täna 12 liiget, kelle seas seitse tarkvarainseneri, kaks andmeteadurit, | |
tarkvaraarhitekt, tooteomanik ning tehnoloogiaskaut. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Initiate pipeline for Named Entity Recognition (ner) | |
ner = pipeline("ner") | |
# The output included encoded classes | |
# Here I give reasonable Estonian names to these classes | |
classes_est = { | |
"O": "Ei ole nimi", | |
"B-MIS": "Nime algus kohe pärast teist nimeüksust", | |
"I-MIS": "Muu üksus", | |
"B-PER": "Inimese nime algus kohe pärast teise inimese nime", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint #for user-friendly output printing | |
# 1. Create a pipeline for text-generation task | |
generator = pipeline('text-generation', model='distilgpt2') | |
# 2. Translate the sentence beginnings from Est to Eng | |
beginnings_origin = [ | |
"Eesti toodab elektrienergiat peamiselt", | |
"Taastuvenergia on oluline, sest" | |
] | |
translated_beginnings = [translate(b, EST_TO_ENG)[0]['translation_text'] for b in beginnings_origin] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. create a pipeline for question answering task | |
respondent = pipeline("question-answering") | |
# 2. Translate the text from Estonian to English | |
context_to_translate = r""" | |
E-Lab on Eesti Energia IT osakonda kuuluv uurimis- ja arendusüksus. | |
Üksuse eesmärk on kiirendada innovatsiooni ja aidata kaasa uute ideede | |
esimeste arendusetappide läbimisele. Kui mõnel äriüksusel on soov innovaatilise | |
IT-lahenduse loomiseks, aitame teostada kontseptsiooni tõestuse ja arendada | |
välja prototüübi. Lisaks testib ja demonstreerib E-Lab ka uusi digitehnoloogiaid, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Translate the text from input language to english | |
input_to_translate = "Parim argument demokraatia vastu on viieminutiline vestlus keskmise valijaga" | |
translated_input = translate(input_to_translate)[0]['translation_text'] | |
# Using the sentiment classifier is oneliner | |
result = classifier(translated_input)[0] | |
print(translated_input) | |
print(f"label: {result['label']}, with score: {round(result['score'], 4)}") | |
# Output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Create sentiment classifier with pipeline function | |
# and the name of the task | |
classifier = pipeline('sentiment-analysis') | |
# 2. Translate the text from input language to English | |
input_to_translate = "Tahtsime parimat, aga välja kukkus nagu alati" | |
translated_input = translate(input_to_translate)[0]['translation_text'] | |
# 3. Using the sentiment classifier is oneliner | |
result = classifier(translated_input)[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
# We use "Helsinki-NLP/opus-mt-et-en" model for translation | |
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-et-en" | |
# Register an account in Hugging Face to get your API_TOKEN | |
# you'll find it under settings | |
headers = {"Authorization": f"Bearer {API_TOKEN}"} | |
# Function to run the post request to the API |
NewerOlder