Skip to content
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

Translate UN Maps Learning Hub contents #267

Closed
yuiseki opened this issue Sep 6, 2023 · 22 comments
Closed

Translate UN Maps Learning Hub contents #267

yuiseki opened this issue Sep 6, 2023 · 22 comments
Assignees

Comments

@yuiseki
Copy link
Collaborator

yuiseki commented Sep 6, 2023

From: https://twitter.com/K_Sakanoshita/status/1699200323779461160

ja (Original):

@yuiseki_
これの日本語版が欲しいけど、相談に乗ってくれそうな方ってご存知でしょうかー。 https://mappers.un.org/learning/

en (by DeepL):

@yuiseki_ I would like to get the Japanese version of this, but do you know anyone who might be able to help me? https://mappers.un.org/learning/

@hfu
Copy link
Contributor

hfu commented Sep 7, 2023

「この文書の日本語版を作りたいのだけど、話を繋いでくれるか」という問いですと、私あたりが繋いでいくということで貢献できそうです。

SMG で日本語版を作りましょう、ということになるとすれば、例えば Open-source LLM でサクサク翻訳しながら作っていきましょう、といったアプローチなら可能でしょうか。

私もこの文書の内容には多少興味があるので、翻訳作業への多少の参加についても興味があります。

作業量の見積もりや作業ルールの検討をしていくと前に進みそうですね。

@yuiseki
Copy link
Collaborator Author

yuiseki commented Sep 7, 2023

Open-source LLM でサクサク翻訳しながら作っていきましょう、といったアプローチなら可能でしょうか

興味深いアイデアです!国連の関連文書の翻訳にOSS LLMを活用しました!(単純な全自動機械翻訳ではなく、人間による適切な校正をしています)!みたいに言えると、インパクトありますね!!

「ぜひ一緒にDWG-7 Smart Mapsでこの文書の日本語版を作りませんか!」と誘ってみるのもアリなのではないか?と思いました。

「OSS LLMを使って国連の関連文書の翻訳にチャレンジしよう!」というテーマだと、関心を持って貢献してくれる人も集まる予感がします。


ところで、 https://mappers.un.org/learning/login/index.php で、どうやったらログインできるのかサッパリわかりませんでした……(笑)

@hfu
Copy link
Contributor

hfu commented Sep 7, 2023

私は 2023-07 に https://mappers.un.org/learning/login/index.php のアカウントを作っていました。

フィージビリティを確認するために、open-source LLMs である程度翻訳ができるか試してみるとよさそうですね。
試した後で、大体どの程度の作業量になるのか見積もって、行けるということになりそうであれば、仲間を募ることと前後しながら、9月または10月のUN Open GIS Monthlyで報告することを目標にUN側の人のネットワークを辿ってみるということができればと思います。

私は今手元の Mac で ./server -m models/llama-2-13b-chat.Q5_K_M.gguf -c 2048 を動かしてみたりしています。この作業に最適なモデルはどれでしょう。その辺りも探っていければと思います。

加えて、作業量見積もりのために、対象コンテンツの概略見取りも進めてみますね。

@hfu hfu changed the title Request for a Japanese version of the UN Maps Learning Hub Translate UN Maps Learning Hub contents Sep 8, 2023
@hfu hfu assigned hfu and yuiseki Sep 8, 2023
@hfu hfu removed the waiting/assign label Sep 8, 2023
@hfu
Copy link
Contributor

hfu commented Sep 8, 2023

本件、かなり有望な貢献候補であるように思えてきました。

作業形成の順序としては、次のような感じでしょうか。

  1. オープンソースLLMでどのくらい行けるか、フィージビリティの確認
  2. 概ねの作業量の見積もり
  3. Sakanoshita さんを含め、有志協力を頂ける方の下募集、有志協力量の概ねの見積もり
  4. 作業に必要な概ねの時間(2ヶ月なのか2年なのか)の見積もり
  5. UN Open GIS Initiative Bureau への報告・相談
  6. UN Maps グループへの連絡・相談
  7. UN Open GIS Monthly への報告

上記のような調整作業を進めながら、正味の作業は上記の調整作業にあまり制約されることなく「できるところから進めていく」というような感じになるでしょうか。

@yuiseki
Copy link
Collaborator Author

yuiseki commented Sep 8, 2023

1. オープンソースLLMでどのくらい行けるか、フィージビリティの確認

非常に参考になりそうなツイートをみつけました

https://twitter.com/voleneko/status/1683033439979851776

Llama-2-7B/13B-chatの機械翻訳性能を検証した
https://staka.jp/wordpress/?p=983

(ほぼ)フリーのLLMの中では性能が高くICL利用時はGPT-3.5に迫る
13Bでこのスコアだと70BのLlama2がChatGPTに匹敵というのは過大評価ではない印象

7B→13Bで性能向上が大きく翻訳には一定のパラメータ数が必要そうで興味深い

https://twitter.com/voleneko/status/1683080723912335360

非常にシンプルでfew shot部分は
 'Translate English to Japanese:\n{} \n -> \n {} \n\n'.format(en, ja)
最後に
 'Translate English to Japanese:\n{} \n -> \n'.format(en)
です

https://twitter.com/goto_yuta_/status/1683100467725996032

ありがとうございます!
シンプルですね!
ちなみに文末に「no explanation」とか「only translation result」とかつけるパターンとかも見かけます!

GGUFに対応した、最新の llama.cppmake します(すでにやっているのならスキップ可):

cd ~
git clone https://github.com/ggerganov/llama.cpp.git
cd ~/llama.cpp
git pull
make

GPUを活用したい場合は以下のように make します(GPUが無い場合は、無視して下さい)

make LLAMA_CUBLAS=1

llama-2-7b.Q4_K_M.gguf を入手します

llama-2-13b-chatである必要は無さそうでした
llama-2-13bである必要すら無さそうでした

https://huggingface.co/TheBloke/Llama-2-7B-GGUF

cd ~/llama.cpp/models
wget https://huggingface.co/TheBloke/Llama-2-7B-GGUF/resolve/main/llama-2-7b.Q4_K_M.gguf

以下のコマンドを実行します:

  • -t の値は自分のCPUの論理プロセッサ数に応じて適切に指定してください。これを論理プロセッサ数と同一にするとOSまで巻き込んでクラッシュするリスクがあるので-2とかしておいたほうが無難です。
  • --gpu-layers の値は自分のGPUに応じて適切に指定してください。GPUが無い場合は、除去して下さい。
./main -m models/llama-2-7b.Q4_K_M.gguf --gpu-layers 43 -t 14 --temp 0 --repeat_penalty 1.1 -p "
Translate English to Japanese:
English:Hello World
Japanese:こんにちは

Translate English to Japanese:
English:The United Nations is an international organization that promotes international cooperation and peacekeeping.
Japanese:国連は国際的な協力と平和維持を促進する国際機関です。

Translate English to Japanese:
English:Through the UN Maps Learning Hub, UN Mappers offers a self-training platform accessible to anyone discovering the OpenStreetMap project and wishing to participate in the improvement of this free geographic database as do many thousands of contributors each month.
Japanese:"

メチャクチャ待ちます

出力されます

Translate English to Japanese:
English:Through the UN Maps Learning Hub, UN Mappers offers a self-training platform accessible to anyone discovering the OpenStreetMap project and wishing to participate in the improvement of this free geographic database as do many thousands of contributors each month.
Japanese:UNマップスラーニングハブは、国際連合地図学習ハブとして、オープンストリートマップの自主的な学習プラットフォームを提供する。

既知の問題

止まらないんです

Image from Gyazo

@smellman
Copy link
Collaborator

smellman commented Sep 8, 2023

MacBook Pro M2Proだと10秒ぐらいで出力されはじめました。
Metalがデフォルトで有効になっているので早いですね。
止まらないのは同じです。

@smellman
Copy link
Collaborator

smellman commented Sep 8, 2023

macOSでサーバ試して見ました。

./server -m models/llama-2-7b.Q4_K_M.gguf -c 2048

https://gyazo.com/ce7d4d552c7fd0e5045eb33d34ee2ab6

https://gyazo.com/55571b62f3b0f125c8d0e6999ecec195

いい感じですね!

@hfu
Copy link
Contributor

hfu commented Sep 8, 2023

ちょうど下記リンク先で遊んでいて、「繰り返しが発生する場合は、 repetition_penalty を1.05〜1.20など調整する」という文章を読んでいました。
https://huggingface.co/spaces/elyza/ELYZA-japanese-Llama-2-7b-fast-instruct-demo

@hfu
Copy link
Contributor

hfu commented Sep 8, 2023

「この英語が言おうとしていることを、分かりやすい日本語で書き直してください。」という言い回しが、割と良いような気がしたりしています。

@hfu
Copy link
Contributor

hfu commented Sep 8, 2023

私も llama-2-7b.Q4_K_M.gguf に揃えて macOS でサーバモードで稼働することができました!

@yuiseki
Copy link
Collaborator Author

yuiseki commented Sep 9, 2023

--repeat_penalty 1.20 にしたらピタッと止まりました!!ありがとうございます!
また、これまで外付けのUSBドライブにllama-2-7b.Q4_K_M.ggufを配置していたんですが、内臓のSSDにllama-2-7b.Q4_K_M.ggufを配置してみたら、爆速で推論してくれるようになりました。これはすごい。普通に無料でLLMs使い放題だ。

input:

./main -m models/llama-2-7b.Q4_K_M.gguf --gpu-layers 50 -t 8 --temp 0 --repeat_penalty 1.20 -p "
# Translate English to Japanese
English: Hello World
Japanese: こんにちは

# Translate English to Japanese
English: The United Nations is an international organization that promotes international cooperation and peacekeeping.
Japanese: 国連は国際的な協力と平和維持を促進する国際機関です。

# Translate English to Japanese
English: Through the UN Maps Learning Hub, UN Mappers offers a self-training platform accessible to anyone discovering the OpenStreetMap project and wishing to participate in the improvement of this free geographic database as do many thousands of contributors each month.
Japanese: "

output(一部):

# Translate English to Japanese
English: Hello World
Japanese: こんにちは

# Translate English to Japanese
English: The United Nations is an international organization that promotes international cooperation and peacekeeping.
Japanese: 国連は国際的な協力と平和維持を促進する国際機関です。

# Translate English to Japanese
English: Through the UN Maps Learning Hub, UN Mappers offers a self-training platform accessible to anyone discovering the OpenStreetMap project and wishing to participate in the improvement of this free geographic database as do many thousands of contributors each month.
Japanese: 国連マップ学習ハブを通じて、UN Mappersは自己教育のためにオープンストリートマップ(OSM)という無料地理データベースへ参加することができます。
 [end of text]

llama_print_timings:        load time =  1783.41 ms
llama_print_timings:      sample time =    42.87 ms /    75 runs   (    0.57 ms per token,  1749.56 tokens per second)
llama_print_timings: prompt eval time =   272.18 ms /   166 tokens (    1.64 ms per token,   609.90 tokens per second)
llama_print_timings:        eval time =  3538.57 ms /    74 runs   (   47.82 ms per token,    20.91 tokens per second)
llama_print_timings:       total time =  3896.12 ms
Log end

4秒以下で終わってます

@yuiseki
Copy link
Collaborator Author

yuiseki commented Sep 9, 2023

オフトピックですが、 llama-2-7b.Q4_K_M.gguf にOverpass API Queryを書く能力があるか調べてみました

Input:

./main -m models/llama-2-7b.Q4_K_M.gguf --gpu-layers 50 -t 8 --temp 0 --repeat_penalty 1.20 -p "
You are an expert OpenStreetMap and Overpass API. You output the best Overpass API query based on input text.

You will always reply according to the following rules:
- Output valid Overpass API query.
- The query timeout MUST be 30000.
- The query will utilize a area specifier as needed.
- The query will search nwr as needed.
- The query MUST be out geom.
- The query MUST be enclosed by three backticks on new lines, denoting that it is a code block.

Examples:
===
Input text:
Area: Lebanon
Output:
\`\`\`
[out:json][timeout:30000];
relation[boundary="administrative"]["name"="Lebanon"];
out geom;
\`\`\`

Input text:
AreaWithConcern: Sudan, Hospitals
Output:
\`\`\`
[out:json][timeout:30000];
area["name"="Sudan"]->.searchArea;
(
  nwr["amenity"="hospital"](area.searchArea);
  nwr["amenity"="doctors"](area.searchArea);
);
out geom;
\`\`\`
===

Useful hints:
Embassies: nwr["office"="diplomatic"]
Hotels: nwr["tourism"="hotel"]

Input text:
AreaWithConcern: Lebanon, Embassies

Output: "

Output(一部):

Output: 
\`\`\`
[out:json][timeout:30000];
area[name=Lebanon]->.searchArea;
(
  nwr[office=diplomatic](area.searchArea);
)
out geom;
\`\`\` [end of text]

llama_print_timings:        load time =  7680.09 ms
llama_print_timings:      sample time =    32.97 ms /    56 runs   (    0.59 ms per token,  1698.72 tokens per second)
llama_print_timings: prompt eval time =   487.00 ms /   337 tokens (    1.45 ms per token,   692.00 tokens per second)
llama_print_timings:        eval time =  2519.69 ms /    55 runs   (   45.81 ms per token,    21.83 tokens per second)
llama_print_timings:       total time =  3077.76 ms
Log end

普通に書けるっぽいです!!しかも早い!

ただし、Llama 2はデフォルトはmax 508 tokenで、OpenAIのtext-davinci-003の4000 tokenよりもだいぶ厳しい。
-c 2048 と指定することで伸ばせるようですが。

@hfu
Copy link
Contributor

hfu commented Sep 9, 2023

翻訳の方でも、「そうだ、課金されないならどんどん長くなっていいじゃないか」という発想で、対訳を一個ずつ継ぎ足していく方法を試してみました。翻訳のクオリティとしては微妙で、翻訳作業のモチベーションを上げてくれるコパイロットとまではいかないかなと思っていますが、ご参考まで共有します。

Getting started with OSM

Published under Creative Commons Attribution – ShareAlike 2.0 Generic https://creativecommons.org/licenses/by-sa/2.0/

If reusing and redistributing this material, you need to mention "source: UN Mappers" and keep the CC-BY-SA 2.0 license

Introduction

English: OpenStreetMap (OSM) is a collaborative online mapping project which aims to build a free geographic database of the world. Anyone can contribute to it, with submitted contributions being instantly integrated into the database / appearing online; and anyone can use the data for free, due to the free data license.

Japanese: オープンストリートマップ(OSM)は世界全体について無料で使用可能な地理空間データベースの建設を目的とした協働ウェブ地図プロジェクトである。どんな人も参加することが出来、即時に掲載されるように提供される情報を基礎としていく。また、任意の者はそのデータをフリーかつ自由に利用することができる。

English: Considered to be the Wikipedia of cartography, this wiki project started in 2004 in the United Kingdom. A very large number of users have since joined this community, its geographic database sustaining a large ecosystem of actors and becoming a reference, especially in the humanitarian and development fields, where alternatives are limited.

Japanese: おおむね「地図版のウィキペディア」と言われているオープンストリートマップ(OSM)プロジェクトは、英国で2004年に始動したコラボレイティブ・ウェブマッピング・プロジェクトであり、多数のユーザーが参加して以来、世界的な地理空間データベースへの様々な関係者の貢献や、特に開発途上国における人道支援活動等において重要な情報源となってきた。また、このプロジェクトを利用する方も自由にフリーかつ無料で使う事が出来る。

English: Constantly updated, mostly from satellite imagery and field collection, the OSM data can be very detailed and of high quality, thanks to a flexible data and attribution model, a wiki documentary source, and numerous control tools. OSM is the source of many services available on the web or on mobile applications.

Japanese: 常時更新されていくように、OSMは主に衛星画像や現場集められた情報に基づいている。高品質だったり尺度が非常に明瞭であることは、ウィキドキュメンタリーソースや多数の制御ツールに起因している。OSMデータベースへの参加者も多く、その結果、様々なサービスがWeb上やモバイルアプリケーション向けに提供されている。

English: It is easy to join the OSM mapping community by creating an account (it takes only a few minutes!) and using one of the many existing ways of interaction.

Japanese: まずはオープンストリートマップ(OSM)コミュニティを作成する手段として、自分用のアカウント(登録時間はわずか5〜10分程度!)を設立し、それに関連付けられた何千通りもの交流方法を使う事が出来るようだ。

A free and non-sensitive geographic database / 自由でありセンシティブではない地理データベース

Translate English into Japanese.

English: From a technical point of view, OSM is not software or a website, but a database. The main one is hosted on a server in Amsterdam and replicated on different servers around the world under the name Planet.osm. The database is operated with the free software PostgreSQL/PostGIS. Currently, in 2022, it contains almost 9 billion point objects and nearly one billion lines or polygons, with a total compressed size of 130 GB.

Japanese: このデータベースは無料で利用可能なオープンソース・サーバーである。主要サーバーはオランダのアムステルダムに位置する。また、各地のOSMコミュニティメンバーによって様々な経路で複製されている。そして、このデータベースを管理するツールとしてはフリーソフトウェア(Free Software)のPostgreSQL/PostGISが使われている。現在2022年時点で、ほぼ9兆点以上の点情報と約千万本もの線や面、合計で大きくて約130GBのサイズで保存されている。

English: The data in the OSM database are free, both for access, modification, sharing and reuse to create derivatives. The content of the OSM database has always been subject to a free license: CC-BY-SA between 2004 and 2012, and ODbL (acronym for Open Database License) 1.0 afterwards. These two licenses allow all uses of OSM data, both commercial and non-commercial, on two conditions:

Japanese: オープンストリートマップ(OSM)データベースにある全てのデータは無料で利用可能なオープン・ソースだったりしており、その中身をアクセスすることが出来、変更することが出来、共有することが出来、新規作成物への使用も自由に行う事が出来る。また、このデータベース内容は常にフリーライセンスによって保障されている。特定の年月から現在まで、CC-BY-SA やODbL(Open Databse Licence) 1.0の二つの権利が含められている。どちらも商業的活動及び非商業的活動双方で、同時に二つの条件が必要:

English: - Attribution. Because the data belongs to its contributors, any product derived from OSM (such as a map using its data) must bear the mention © OpenStreetMap contributors

Japanese: - 帰属。データは貢献者に属することから、OSMから作られたあらゆるプロダクト(例えばそのデータを使った地図)は (c) OpenSteetMap contributors という言及をしなければならない。

@hfu
Copy link
Contributor

hfu commented Sep 9, 2023

上記の実験結果は https://hackmd.io/@hfu/rkVeNdK0h に置いています。

@yuiseki
Copy link
Collaborator Author

yuiseki commented Sep 9, 2023

翻訳の叩き台としては充分なのではないかと思いました!

そもそも、Llama 2だけで超正確に翻訳することは、かなり難しいと私は考えています。
それでも、「英語をざっくりと日本語に翻訳する」という作業はLlama 2にやらせて、「日本語の不自然さやニュアンスなどを校閲する」という作業を人間がやれば良いというのは、大幅な作業負担の軽減になるはずです。
オープンライセンスの辞書もあるはずなので、プロンプトで「この単語はこう訳すといいかもよ」のような軽いヒントを与えれば、カタカナに変換するだけというのも防げそうに思いました。

噂によると70Bにすると翻訳性能含め一気に「賢さ」が上がるらしいのですが、70Bのモデルを動かすためには膨大なメモリが必要で、OpenMPIによって複数台のマシンで分散処理するという機能は主にこの問題のために開発されている様子です。

@hfu
Copy link
Contributor

hfu commented Sep 14, 2023

国連憲章について、実験用に入力してみました。これを llama2 にプロンプトとして入れると、意訳的な何かを出力してくれます。

https://hackmd.io/@hfu/multilingual-un-charter/edit

@hfu
Copy link
Contributor

hfu commented Oct 11, 2023

#281 でのディエゴ情報によれば、UN Maps Learning Hub をベースに learning platform を作っていくという構想があるようです。引き続き注目していきたいと思いました。

@yuiseki
Copy link
Collaborator Author

yuiseki commented Oct 12, 2023

UN Maps Learning Hubのお話は非常に興味深かったですね!私もUNのCertificateほしいと思いましたw

@hfu
Copy link
Contributor

hfu commented Oct 31, 2023

ソウルで Diego Gonzalez と本件打合せができるかもしれませんね。打合せの材料を我々のプロジェクトとして積み上げていく、ということは試してみることができるかも知れません。

@hfu
Copy link
Contributor

hfu commented Jan 11, 2024

この件、実施に至る結果にならなさそうな雰囲気がありますね...。
いったんクローズしてもいいかも。

@yuiseki
Copy link
Collaborator Author

yuiseki commented Jan 12, 2024

いったんクローズしてもいいかも。

+1です

@hfu
Copy link
Contributor

hfu commented Jan 13, 2024

クローズします!

@hfu hfu closed this as completed Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants