Skip to content

Feat/evergreen #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feat/demo_1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/assets/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ model(['Was in the city yesterday - didn’t notice anything strange'])`,
[Snippets.restApi]:
"python -m deeppavlov riseapi insults_xlm_roberta_base -di",
},
evergreenClassification: {
[Snippets.cli]:
"python -m deeppavlov interact evergreenqa_bert -di",
[Snippets.python]: `from deeppavlov import build_model
model = build_model('evergreenqa_bert', download=True, install=True)
model(['In what year was Pushkin born?'])`,
[Snippets.restApi]:
"python -m deeppavlov riseapi evergreenqa_bert -di",
},
intentClassification: {
[Snippets.cli]:
"python -m deeppavlov interact intents_distilbert_base_multi -di",
Expand Down
24 changes: 23 additions & 1 deletion src/components/BaseSkill/BaseSkill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class BaseSkill extends Component<Props, State> {
return answers.map(this.renderQA)
} else if (renderAnswer.type === "insult") {
return answers.map(this.renderInsult)
} else if (renderAnswer.type === "evergreen") {
return answers.map(this.renderEvergreen)
} else if (renderAnswer.type === "sentiment") {
return answers.map(this.renderSentiment)
} else if (renderAnswer.type === "emotion") {
Expand All @@ -177,7 +179,7 @@ class BaseSkill extends Component<Props, State> {
return answers.map(this.renderTopic)
} else if (renderAnswer.type === "entitylinking") {
return answers.map(this.renderEntityLinking)
}
}
}
renderEntityLinking = (mes: Answer, i: number) => {
const rest = { ...mes }
Expand Down Expand Up @@ -289,6 +291,26 @@ class BaseSkill extends Component<Props, State> {
</div>
)
}
renderEvergreen = (mes: Answer, i: number) => {
const { colors } = this.props.renderAnswer!
const answer = mes.answer[0].toString().toUpperCase()

return (
<div className={s.basic} key={i}>
<p>
<span
className="card"
style={{
backgroundColor: colors![answer === "1" ? "EVERGREEN" : "NON_EVERGREEN"].color!,
}}
>
{answer === "1" ? "EVERGREEN" : "NON_EVERGREEN"}
</span>
</p>
<p>{mes.question}</p>
</div>
)
}
renderTopic = (mes: Answer, i: number) => {
const { colors } = this.props.renderAnswer!
const answer = mes.answer[0].toString().toUpperCase()
Expand Down
1 change: 1 addition & 0 deletions src/components/BaseSkill/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface RenderAnswer {
| "ranking"
| "intent"
| "insult"
| "evergreen"
| "sentiment"
| "topic" // new - here and below
| "textsentiment"
Expand Down
2 changes: 2 additions & 0 deletions src/components/Classes/Classes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
topicClasses,
sentimentClasses,
insultClasses,
evergreenClasses,
emotionClasses,
Classes as ClassesList,
} from "utils/utils"
Expand Down Expand Up @@ -36,6 +37,7 @@ export const Classes: FC<ClassesProps> = (props) => {
[Links.textTopic]: topicClasses,
[Links.textSentiment]: sentimentClasses,
[Links.textToxic]: insultClasses,
[Links.textEvergreen]: evergreenClasses,
[Links.textEmotion]: emotionClasses,
}

Expand Down
71 changes: 71 additions & 0 deletions src/pages/TextClassification/EvergreenQA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import axios from "axios"
import React from "react"
import skillWrapper, { BaseSkillProps } from "components/BaseSkill"
import { Res } from "lib/api"
import { scripts } from "assets/scripts"
import { evergreenClasses } from "utils/utils"

interface Req {
question: string
}

const config: BaseSkillProps<Req, Res> = {
title: "EvergreenQA Classification",
desc: (
<p>
EvergreenQA classification is used to determine whether questions have answers that never change - "Evergreen", -
and therefore require no extra information to be provided to an LLM for answer generation,
or they have answers that typically change over time - "Non_Evergreen", - and thus an LLM should be provided
with specific information that might have changed over years or months.
To learn more on implementation read our{" "}
<a href="https://docs.deeppavlov.ai/en/master/features/models/classification.html">
documentation
</a>
.
</p>
),
docker: "deeppavlov/evergreen_en",
inputs: [
{
title: "Text",
type: "textarea",
name: "question",
},
],
examples: [
{
question: "When was America discovered?",
},
{
question: "Who is the current Formula 1 champion?",
},
{
question: "Combien de jours y a-t-il dans une année?",
},
{
question: "Combien de temps faut-il pour voyager en train de Moscou à Vladivostok ?",
},
{
question: "В каком году было последнее солнечное затмение?",
},
{
question: "В каком году был проведён первый чемпионат мира по футболу?",
},
{
question: "Где находится самое высокое здание в мире?",
},
],
api: async (stateReq: Req) => {
const req = {
x: [stateReq.question],
}
return await axios.post("http://127.0.0.1:5025/model", req)
},
renderAnswer: { type: "evergreen", colors: evergreenClasses },
snippets: scripts.textClassification.evergreenClassification,
}

const Evergreen = skillWrapper<Req, Res>("evergreen")
export default function () {
return <Evergreen {...config} />
}
2 changes: 2 additions & 0 deletions src/router/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NER from "pages/TokenClassification/NER"

import ODQA from "pages/QuestionAnswering/ODQA"
import ReadingComprehension from "pages/QuestionAnswering/ReadingComprehension"
import EvergreenQA from "pages/TextClassification/EvergreenQA"

// prettier-ignore
export const Router = () => (
Expand All @@ -21,6 +22,7 @@ export const Router = () => (
<Route path={`/:tab/${Links.textEmotion}`} exact component={Emotion} />
<Route path={`/:tab/${Links.textTopic}`} exact component={Topic} />
<Route path={`/:tab/${Links.textToxic}`} exact component={Toxic} />
<Route path={`/:tab/${Links.textEvergreen}`} exact component={EvergreenQA} />
<Route path={`/:tab/${Links.textSentiment}`} exact component={Sentiment} />
{/* <Route path={`/:tab/${Links.textFewShot}`} exact component={TextFewShot} /> */}

Expand Down
6 changes: 6 additions & 0 deletions src/router/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Intent from "pages/TextClassification/Intent"
import NER from "pages/TokenClassification/NER"
import ODQA from "pages/QuestionAnswering/ODQA"
import ReadingComprehension from "pages/QuestionAnswering/ReadingComprehension"
import EvergreenQA from "pages/TextClassification/EvergreenQA"
// import EntityLinking from "pages/TokenClassification/EntityLinking"
// import KnowledgeBaseQA from "pages/QuestionAnswering/KnowledgeBaseQA"
// import { TextFewShot } from "pages/TextClassification/TextFewShot"
Expand All @@ -22,6 +23,7 @@ export enum Links {
textTopic = "text_topic",
textSentiment = "text_sentiment",
textToxic = "text_toxic",
textEvergreen = "text_evergreen",
textEmotion = "text_emotion",
textFewShot = "text_few_shot",
tokenNer = "token_ner",
Expand Down Expand Up @@ -67,6 +69,10 @@ export const routesForDemo: Routes = {
{ title: "Toxicity",
link: Links.textToxic,
component: Toxic },
{ title: "EvergreenQA",
link: Links.textEvergreen,
component: EvergreenQA
},
{ title: "Emotion",
link: Links.textEmotion,
component: Emotion },
Expand Down
5 changes: 5 additions & 0 deletions src/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const insultClasses = {
INSULT: { color: colors.red },
NOT_INSULT: { color: colors.green },
}
const evergreenClasses = {
NON_EVERGREEN: { color: colors.red },
EVERGREEN: { color: colors.green },
}
const sentimentClasses = {
NEGATIVE: { color: colors.red },
POSITIVE: { color: colors.bottlegreen },
Expand Down Expand Up @@ -356,6 +360,7 @@ export {
renderNerClasses,
ontonotesClasses,
insultClasses,
evergreenClasses,
sentimentClasses,
topicClasses,
emotionClasses,
Expand Down