Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 code. Please 1 from h1dden_11b 1mport count trigrams 2 from h1dden_11b 1mport tra1n class1f1er Write a function score_document (document, lang_counts default_lang_counts) which takes

Python 3 code. Pleaseimage text in transcribed

1 from h1dden_11b 1mport count trigrams 2 from h1dden_11b 1mport tra1n class1f1er Write a function score_document (document, lang_counts default_lang_counts) which takes as input a document name as a string and a dictionary of dictionaries containing normalised language counts called lang_counts. It should return a dictionary of scores for each language in lang_counts, as obtained by performing a 'dot product' of trigram counts from the document with the normalised language counts. That is, it should multiply the trigram counts from the document with the trigram counts in lang_counts and add the whole lot up. If a trigram from the document is not in the dictionary for a given language, assume the count for the language as zero. 4 # We train the class1 fler here default-lang-counts tra1n. class1 fler('tra1n.csv.) 5 6 7 def score_document (document, lang_counts-default_lang_counts): # Your code here pass We have provided a stub of code which trains the classifier for you. We have also provided tra1n classifier (tra1ning set) in a hidden library There are also two files included, visible in the tabs at top right. These are en-16 383. txt. Written in English, and de-123 1811 . txt. written in German, and can be loaded and used to test your function, which should behave as follows: >>> test1 = 'en 163083.txt' >>> d = score-document (test1) >>> dNV1etnamese 9.427325768357315 >>> max ([(v, n) for (n, v) 1n d.1tems ()]) (21.428216914833023, 'Engl1sh') >>> test2 'de 1231811.txt' >>> d score document (test2) 7.710346556417009 >> max ([ (v,n) for (n, v) 1n d.1tems )]) (53.12937809633241, German)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions