The site derives its data from a number of sources, with the information being plugged in requiring cleansing, and critically for ease of use with this website. classification. This methodology is recorded below. The below was envisioned, carried out and recorded (in Japanese) by Chisako, then translated into English by Aaron.

Machine Learningによる日本語Eメールの分

Classifying Japanese Emails through the use of Machine Learning

 

プロジェクトの背

 現在世界の日本語学習者数は約385万人いると言われており、アジア圏を中心に増加を続けている。それら学習者の日本語学習の動機は主に日本の漫画やアニメへの興味、歴史や文学・芸術への関心であり、そういった人々のために様々な機関で日本語教育が行われており、またテキストブックやインターネット上のリソースも豊富に存在する。一方で、日本語を仕事などで必要に迫られて学ぶ人は比較的少なく、実際に日本語学習者への調査では「仕事で必要」と答えた人は20%に満たない。そのため、仕事のための日本語を学ぶためのリソースは限られており、実際の現場で仕事をしながら学んでいくことが多い。特に敬語に関する学習リソースは、一般的な日本語学習の一部として多く存在するものの、仕事で使用する様々な言い回しや、文書やメールの書き方などに関して豊富なサンプルを含んだ体系的、かつ英語など学習者にとって理解しやすい言語で記載された文献はほとんど存在していない。当プロジェクトは、そういった問題を解決する文献を作成するメインプロジェクト(Kooma Mails)の一部として発足し、特に現在のビジネスシーンで人々が最も時間を使っているであろEメールの文例を提供するものである

 

Project Background

It is believed that there are​​ currently about 3.85 million Japanese-language learners, with the increase focused largely in the Asian region. A big incentive for such people to study Japanese primarily comes from interest in pop culture, such as Manga or Anime, History & Linguistics, or even art. For them, there is a wealth of information related to learning Japanese, whether that be online resources or textbooks. That said, there is, currently, a comparatively fewer number of people studying Japanese for work purposes; in a survey of Japanese learners,​​ less than 20% said they were studying for use of the language at work. As a result, it isn’t surprising that there is a limited amount of resources for Business Japanese learners, and there are a lot of cases where people are forced to study, in essence, as part of “on the job” learning.​​ 

Though there exists a large amount of resources covering general Japanese language learning, there is a real​​ lack of educational resources that cover Keigo​​ (i.e. business formal Japanese). This can include particular phrases, as well as particular sentence structures and emails writing styles. Thus, we see very few​​ systemic/cohesive offerings, such as Keigo-writing sample depositories, and in tandem with that, a lack of resources explaining how, and why, certain words or phrases are used in such writing samples.​​ This project aims to try and solve this problem – namely, the lack of centralized resources, with the accompanying grammatical explanations you would expect of a standard textbook. We have dubbed this effort (our main project),​​ Kooma Mails. Emails are typically what people in the larger business scene spend the most amount of time on, so we aim to offer helpful examples and advice to make that process easier, and more straightforward, to learn.

 

 

プロジェクトの目的と概

 本プロジェクトの目的は、実際に仕事の現場でやり取りされたEメールを抽出・加工し、学習用サンプルとして、よりリアルで実践的なEメールのライブラリを提供することである。良質なサンプルライブラリの構築のためには適切な分類と、サンプルとして足る品質を保証することが重要である。しかし日々の業務の中では膨大な量のEメールが発生し、それらを人手で精査・分類することは容易ではない。そこで今回は、実際のEメールをインプットとし、固有名詞・個人情報、不要な情報(外部ウェブサイトへのリンク等)の置換といったデータクリーンアップ、Deep Learningを用いた内容の解析と分類の一連の処理を自動化するプログラムを開発することとした

 

Project Purpose​​ & Abstract

The purpose of this project, is to provide (for learning purposes) a large database of real-life & generated examples of email communication between individuals, so that it can be used as a “library”, with a variety of real & practical examples that can be followed or modeled-after. In order to construct a good, useful library, 2 things are necessary: appropriate tags/categories, and quality samples. However,​​ given the large quantity of​​ emails received​​ day-to-day, it​​ is not a simple task to carry out the analysis and sorting process.​​ 

 

Thus, we’ve have created a program to streamline this process. It functions as such:​​ 

  • The email is input into the system, then, proper nouns, personal identifiers, or otherwise unnecessary information (external website links etc.) are switched-out or deleted as part of the “data cleansing” process

  • Then, using Deep Learning, the contents are analyzed and categorized as part of a single automatized process. The out-put email is able to be freely used and shared.

 

 

開発環境および使用パッケージ・サービス

Tools & Packages used in Analysis & Development

Python 3.X.X

Jupyter Notebook

fastText X.X.X

Doc2Vec X.X.X

COTOHA API (URL)

 

 

処理プロセス

 

  • Input

    • Mbox形式のEメール(1ファイル)

  • Output

    • CSV形式クリーニング・データマスク済、分類済Eメール(個別ファイル

 

ステップごと

 

1)​​ Mbox形式ファイルの読み込

  • Mailboxパッケージを使用し、mboxファイルをインポー

  • メールオブジェクトからメッセージボディを抽出
    メッセージボディがマルチパートであるかを判断し、コンテントタイプが”text/plain”のもののみをメール本文と判断し、適切な文字コードにデコードして取得する。改行コードは後述の言語判定処理にて邪魔になるため、この段階で同時に除去する。またメールの引用部分も本文解析には必要ないため、引用時のヘッダーを正規表現で抽出し削除する。後述のステップで不要情報を削除しているが、引用部分に関しては言語判定に影響してしまうため、先に除去しておく

  • 本文の言語(英語/日本語)を判定
    判定にはfastTextの言語判定用モデル(lid.176.bin)を使用した

    • メールオブジェクトから下記の情報を抽

      • メッセージID

      • 送信日

      • 送信元アドレ

      • 送信先アドレ

      • タイト

    • 抽出した本文、言語判定結果、メッセージID等のメタデータをCSVファイルとして出力
      次のステップでは日本語のメールのみを対象として分類を行うため、言語判定結果をキーに英語メール、日本語メールの2ファイルを作成する。

2)​​ 固有名詞リストの作

  • で保存した日本語メールのCSVを読み込

  • 対象となるメールタイトル、本文をリクエスト用のブロックに加工
    COTOHA API
    の無料アカウントではリクエストが1000コール/日と限られているため、1リクエストに複数のメールタイトルと本文を含めることとした。APIからのレスポンスを解析し、カテゴリごとに分

  • 結果を置換対象リストとしてCSVファイルに出力して保存

3)​​ 固有名詞・個人情報、不要の部分の削

  • 置換対象リストのCSVに置換後の語句を追記(Excelまたはテキストエディターで実施

  • リストと日本語メールCSVを読み込

    • 日本語メール内の固有名詞・個人情報を置換語句リストに記載された語句に置

  • 日本語メール内にURLをダミーのものに置換
    正規表現を使用し、”http://””https://”等のキーワードでマッチするものを置換す

    • 日本語メール内の電話番号・郵便番号等をダミーのものに置換
      正規表現を使用し、桁数・電話番号・郵便番号フォーマットにマッチするものを置換す

  • 日本語メールをCSVに出力して保存

 

4)​​ Deep Learningを用いた分類(開発中

  • 日本語メールCSVを読み込

  • Doc2VecのPre-trainedモデルを読み込み

  • K-means法を用いて教師なし学習を行い、日本語メールをクラスタリング

  • 分類したカテゴリに応じて、メールを保存する

 

 

Analysis Process

 

  • Input

    • A single file containing all the emails, in Mbox format

  • Output

    • A​​ file of each individual email in CSV format – this file has been cleaned (with​​ any personal data masked) and categorized

Step-by-Step Process

 

  • Process for Reading Files in Mbox Format

    • Using the Mailbox package, the Mbox file is input

    • The body of the message is extracted from the mail object
      The system determines whether the message body is in multiple parts,​​ makes sure that the body is only “text/plain”,​​ then decodes it into the appropriate character code, then obtains/finalizes the information.​​ The newline character, as it gets in the way of the language detection process (which will be explained later), is also removed at the same time during this stage. Also, in the process of extraction, other emails in the same thread are included with the singular email we want to analyze. For this reason, a few extra steps are undergone at this stage. For one, as the contents of other emails are not analyzed at this step, the header is extracted as a “regular expression” then removed. Unnecessary information is also removed (discussed further in the steps below). Also, as threads may move between multiple languages, confusing the language determination systems, they are also removed – all emails need to be analyzed separately as individual pieces. ​​ 

    • The language of the email (English/Japanese) is determined
      For this determination, fastText (a pre-trained model for determining language (lid.176.bin)) is utilized

    • From the mail object, the following information is extracted:

      • Message ID

      • Time & Date Email was Sent

      • Sender Address

      • Receiver Address

      • Title

    • For the extracted email, the language is determined, and thed above meta-data (message ID etc.) is included, with ultimate output into a CSV file
      As the goal of the system ultimtaley revolves around the analysis and categorization of Japanese emails (as explained in the following steps), for emails determined to be in English, it is put into a separate, 2
      nd​​ file from the Japanese email.

  • Creating a List of Proper Nouns

    • Then, the saved list of Japanese e-Mails files (CSV format) are put into the system to​​ be read

      • The text and title of each email is taken and packaged into a single “block”, put together in a way that can be sent to Cotoha’s API. Since a free account is being used, there is a limit on how many calls can be sent per day (1000 calls), thus emails are sent in as large-of blocks as possible (with their text & headings), and sent as a single request. The result from the API is analyzed, then categorized accordingly.​​ 

      • The result is that words/names that need be exchanged/changed are exported in a CSV “Exchange File”, and saved

  • Process: Removing Names/Proper Nouns, Personal Identifiers & Unnecessary Information

    • Based on the Exchange File, the words/phrases to be added in replacement are appended & added, and saved in a “Post-Exchange File” (Carried out in Excel or Text-Edit app)

    • The list and Japanese-email file are loaded

    • In the Japanese emails, the proper nouns and personal identifying information are exchanged with this “Post-Exchange File” to removal any personal particulars

    • Any URLs in the Japanese emails are swapped out with dummy links
      Using regular expressions, anything matching keywords such as​​ ”http://”​​ or “https://” are exchanged/removed

    • Any phone numbers or addresses are also swapped out with dummy data
      Using regular expressions, anything in the format of numbers & figures, phone numbers, or addresses are exchanged/removed

    • These ‘cleaned’ Japanese emails are exported as a CSV file and saved

  • Using Deep Learning to Categorize Emails (In development)

    • The CSV file with Japanese emails is loaded

    • Doc2Vec’s Pre-trained​​ Model is loaded​​ 

    • Using the K-means method, a model with unsupervised learning is used, and the Japanese emails are clustered accordingly

    • Emails are then finally saved based on their related category

 

 

参照サイト

Resource & Citation List

https://fasttext.cc/

https://mzryuka.hatenablog.jp/entry/2018/11/18/053000

https://github.com/alejandro-g-m/Gmail-MBOX-email-parser

https://stackoverrun.com/ja/q/1821548

https://qiita.com/jsaito/items/a058611cf9386addbc12

https://developers.wonderpla.net/entry/2017/10/10/110000

https://qiita.com/shima_x/items/196e8d823412e45680e9