Phillip
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Technical Description of Topic Modeling in *impresso* In this blog, we give a brief description of the technical steps of applying topic modeling on the impresso corpus. Please find below, the tools and ressources used, the details of the preprocessing and finally, the output of the topic modeling. ## Tools used: We use the following tools for the preprocessing steps and the computation of our topic models: - [`langid.py`](https://github.com/saffsd/langid.py) and [`langdetect`](https://pypi.org/project/langdetect/) for language identification - [spaCy](https://spacy.io/) for linguistic preprocessing - for German (de) tokenisation, Part-of-Speech (PoS) tagging and lemmatisation, as well as Named Entity Recognition (NER): - `de_core_news_sm` - for French (fr) tokenisation, PoS tagging and lemmatisation, as well as NER: - `fr_core_news_md` - for English (en) tokenisation, PoS tagging and lemmatisation, as well as NER: - `en_core_news_sm` - for Luxembourgish (lb) tokenisation, PoS tagging and lemmatisation: - no core model available, we used recently developed [language resources](https://github.com/PeterGilles/Luxembourgish-language-resources) for lb - [GERTWOL](http://www2.lingsoft.fi/doc/gertwol/) for morphological analysis for de - [MALLET](http://mallet.cs.umass.edu/) for topic modeling ## Resources used: - [Morphalou](http://www.cnrtl.fr/lexiques/morphalou/) for additional lemma information for fr ## Data preprocessing Before applying topic modeling to our data, we carry out some preprocessing steps. They include linguistic preprocessing and further measures in order to reduce the text input size. This guarantees that we do not run into memory issues. ### Language identification In a first step, we used `langid` and `langdetect` in parallel to determine the language of an article or newspaper page (since not all newspapers have article segmentation at their disposal). We restrict the two tools to recognise de, fr, en, and lb only. In order to arrive at a final decision about the article or newspaper page language, we take into consideration possible available language information from metadata, as well as the dominant language of the newspaper *per se*. The identified language of an article or page informs which model to use for the linguistic preprocessing with spaCy. It takes the json represenation of an issue as input and outputs a json-file which contains all the language information for a specific newspaper. The recognised `en` articles or pages rarely represents material which had been printed in that language, but rather is the "fallback" if language identification is not sure whether `de`, `fr`, or `lb` is most fitting. #### Example output ``` {"tp":"ar","cid":"diekwochen-1847-10-02-a-i0004","len":420,"orig_lg":"lb","langdetect":[{"lang":"fr","prob":1}],"langid":[{"lang":"lb","prob":1}]} ``` The object of type `ar` = article has received two different results from `langid` and `langdetect`. Since the metadata information `orig_lg` reads `lb`, we decide to attribute `lb` as language to this article. Sidenote: `langdetect` cannot detect `lb`. ### Linguistic preprocessing The linguistic preprocessing processes each newspaper and iterates over articles or pages and performs tokenisation, PoS tagging and lemmatisation, as wella as NER (not for lb). For lb, it maps the PoS tags to [UPOS tags](https://universaldependencies.org/u/pos/). The input is the json representation of an issue (from which we extract the full text of each article or page), while the output consists of a json file enriched with token information, PoS tags, lemmas, NER information in the IOB format, as well as the entity type. #### Example output ``` { "ts": "2019-12-14T10:56:15", "id": "NZZ-1947-01-08-a-i0004", "sents": [ { "lg": "de", "tok": [ { "t": "Kantonsschule", "p": "PROPN", "l": "Kantonsschule", "o": 0, "e": "B-ORG" }, { "t": "Zürich", "p": "PROPN", "l": "Zürich", "o": 14, "e": "I-ORG" }, { "t": "Aufnahme", "p": "NOUN", "l": "Aufnahme", "o": 21 }, { "t": "nouer", "p": "ADJ", "l": "nouer", "o": 30 }, { "t": "Schiller", "p": "NOUN", "l": "Schiller", "o": 36 }, { "t": "für", "p": "ADP", "l": "für", "o": 45 }, ``` We define a list of sentences per article or page, where each sentence receives the language information from the language identification. We add a PoS tag `p`, lemma `l`, character offset `o`, and entity type `e` (where available) to token `t`. ### Topic modeling Since the entire text corpus is too big in order compute topic models in an acceptable amount of time (or in order to be able to compute the model at all), the specific preprocessing pipeline for topic modeling shrinks the data with the help of the following steps: #### Frequency statistics On each language (`de`, `fr`, `en`, `lb`), we compute token frequency statistics in order to identify the relevant vocabulary. We use the frequencies in order to determine whether we want to keep a word for the computation of the topic model or not. Our pipeline accepts minimum and maximum frequencies (see below). ##### Example output ``` 5073076 Jahr 4082589 Uhr 3816752 unb 3243788 Zürich 2626190 Frau 2494486 ber 2351610 Tag 2287781 Zeit 2101611 Herr 1879676 Schweiz 1796776 Land 1628325 ben 1556415 Mann ``` #### Morphological analysis for `de` We pass the frequency statistics for `de` through GERTWOL to perform a morphological analysis. If GERTWOL recognises a word, we include it along with its lemma and PoS tag in our resource for `de`. For `fr` we use Morphalu, for `lb` and `en` we do not use external resources at the moment. ##### Example output ``` Jahr NN Jahr Uhr NN Uhr Zürich NE Zürich Frau NN Frau Tag NN Tag Zeit NN Zeit Herr NN Herr Schweiz NE Schweiz ``` #### Filtering In a next step, we pass the texts through a filtering procedure. We only want to consider nouns (NOUN) and proper nouns (PROPN) in an article or page for the computation of the topic models. This is because they are most descriptive for topics. There is a possibility to recognise proper nouns which consists of multiple tokens and to concatenate them, e.g., if "new york" occurs in a text, it would show as "new_york" after the filtering. This measure increases vocabulary size drastically, and we do not use this feature until we have a frequency filter for multiword named entities. More over, we include a word in the filtering result only if it occurs between the minimum and maximum frequency bounds we obtained from our frequency staticstics. Tokens which occur on a negative lemmas list (stop list) are discarded. The filtering produces a .tsv-file with the article or page identifier, a DUMMY label, followed by the remaining tokens (only NOUN and PROPN), which corresponds to the MALLET input file format. ##### Example output ``` actionfem-1936-02-15-a-i0001 DUMMY INHALT Reform Ehescheidung Teil Seite Mode Welt Teil Interessant Haarpflege Grippe Hauswirtschaft Küche Hausfrau Einfluss Lache actionfem-1936-02-15-a-i0002 DUMMY Grippe Prophylaxe Therapie Atemzug Körper Fältchen Mundhöhle Rolle Eingangspforte Kampf Blutkörperchen Speichel Fähigkeit Infektion Widerstandsfähigkeit Erkältung Oberhand Infektionskrankheit Grippe Erreger Bazillus Sprechen Husten Teilchen Nähe Gefahr Ansteckung Kino Theater Strassenbahn Erhaltung Gesundheit Wichtigkeit Ansteckungsgefahr Grippe Infektionskrankheit Scharlach Kinderlähmung Disposition Mittel Prophylaxe Paul_Ehrlich Altmeister Chemotherapie Wirkung Agens Konzentration Lösung Verlauf Grippe Genüge Fieber Kopfschmerz Mattigkeit Sekret Wirkung Schleimhäute Hebung Folge Wirkung Mittel Grippe Influenza ``` #### Sampling Since computing topic models on all our resources, especially for `de` and `fr`, takes up too many resources, we decided to randomly sample up to 6 million articles or pages per language. We only include articles or pages which contain at least 10 nouns or proper nouns after the filtering process. Before training, we need to convert the sample to a .mallet file (a vectorised input format of the text). We need to do the same for the filtered text from the step before, since we need this for topic inference. We use the the .mallet file of the sampled version as a pipe, since tokens from the filtered version need to get the same index as they got in the .mallet file constructed from the sample. #### Training We instruct MALLET to produce the `topickeys` (top `n` most frequent words per topic), the `doctopics` (the topic distribution of the articles and pages of the sample used for training the topics), the `topicdocs` (the top 100 proportions of each topic in the documents), the `topicwordweights` (importance of each word for a topic), the `model`, and the `inferencer` from the sampled texts (the .mallet version). We train one topic model per language. We extract 100 topics from each language sample. Training on 50 cores takes 2.5 hours for `de`, 1.5 hours for `fr`, 30 minutes for `lb`, and 1.5 hours for `en`. #### Inference We use the inferencer to infer the topics of the filtered texts, since only a fraction of all the texts (the 6 million sample) got topic distributions. #### Generate input for indexing The last step consists of generating the input for indexing the topic information into SOLR. We generate a json file which contains the topic distribution for each article or page. We only take topics into account which make up at least 2% of the overall topic distribution. Another json file summarises the topic information of the 100 topics, where we limit the number of words which are displayed per topics to 150.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully