2024.02.28

LLMLinguaが切り拓くAIアプリケーション開発の新境地: プロンプト長大化問題への処方箋

導入

こんにちは。グループ研究開発本部 次世代システム研究室のH.Oです。

2022年末のChatGPTの登場、2023年のOpenAIによる新機能のリリースに伴い、今やChatGPTを使いこなし、OpenAIのAPIをアプリケーションに組み込むスキルはエンジニアにとって必須になっている様相です。
今回もLLMを用いたアプリケーション開発に関する話題をお届けしたいと思います。
前回の記事では、検索拡張生成(RAG)という、外部から知識情報をOpenAIなどのLLMに与えてやることで特定のドメインについての回答精度を上げていく手法と、Assistants APIを使用した実装について紹介しました。

これに関連して、2023年12月7日に、長大なプロンプトを効率的に圧縮できる極めて画期的なフレームワーク、LLMLingua / LongLLMLinguaがMicrosoftから登場し、注目を集めています。RAGを構築してLLMのAPIを叩くと、長大なプロンプトが送信され、場合によってはトークン数の制約に引っかかるということもしばしばあります。LLMLingua / LongLLMLinguaは、こういった問題にアプローチし、RAGの実装にも大いに貢献するフレームワークです。今回は公開されている2本の論文をもとに、その仕組みと実装について詳しく紹介していきたいと思います。


目次

  • 導入
  • 結論ファースト
  • プロンプト長大化問題とは
    • 背景
    • 課題
  • 解決策
    • 今回対応するタスク
    • 技術スタック
    • 解決策(実装例)
    • 結果
    • うまくいかなかった点
  • LLMLingua の仕組み詳説
    • 予備知識
      • Perplexity
      • Selective-Context
    • LLMLinguaの理論的解説
      • 問題の定式化
      • 3つのモジュール
      • 実験の結果
      • 論文の結論とLLMLinguaの限界
    • LongLLMLingua
  • まとめ
    • 所感
    • 結論
  • 参考資料
  • 最後に
 

結論ファースト

  • LLMLingua / LongLLMLinguaは、膨大なトークン数に膨らんだ長大なプロンプトを、その中に含まれる重要な情報を適切に残したまま圧縮することで、LLMに送信するトークン数を大幅に削減しつつ応答の精度を維持することができる
  • OpenAIなど、LLMのAPIを使ってアプリケーションを作る際、LLM Lingua / LongLLMLinguaを使用することで、経済的コストを大きく削減することができる。また、従来よりもより多くの外部情報を効率的に扱うことができるようになる
  • 注意点として、日本語の外部情報を圧縮すると実用には供さないレベルのアウトプットになる。日本語での運用には大きな課題が残る。

プロンプト長大化問題とは

背景

LLMを用いたアプリケーションの構築には、適切なプロンプトを構築するプロンプトエンジニアリングの技法が必要不可欠です。主な技法として、以下の三つのチューニング手法が有名です。


  • Chain-Of-Thought(CoT)
    中間的な推論ステップを介して複雑な推論能力を可能にします。few-shot promptingと組み合わせることで、推論が必要なより複雑なタスクでより良い結果を得ることができます。
  • In-Context Learning(ICL)
    モデルが与えられた入力のコンテキストに基づいて新しいタスクを理解し、適応する能力あるいはその能力を学習すること。
  • 検索拡張生成(RAG)
    あらかじめLLMに与えた知識情報をベクターデータベースに保存し、質問に関連の深い知識情報を検索する。その検索結果をプロンプトに付加してLLMに送信する

これらは、基本的にLLMに与えるプロンプトに精緻な回答を導くための付加情報を追加するという方向性が共通しています。その結果、LLMに与えるプロンプトがますます長大になっていきました。


課題

LLMに与えるプロンプトが長大化することによって次のようなパフォーマンスの低下が問題になります。


  • コンテキストウィンドウの制限超過
  • 高額なAPI課金
  • レイテンシーの増大
  • 関連情報の検索精度が落ちたり、情報が失われたりする

実際に前回の記事の執筆に際してRAGを構築した際にも、uploadするファイル数を増やしていくと、LLMに送信するトークン数の制限に引っかかるといった問題に直面しました。

従来はcompressionや量子化によるパラメータ修正で対応しようとしていましたが、LLMがAPI経由でしか使用できないときにはLLMはブラックボックスとなっているため、効果を発揮できないという問題が残ります。

これらの問題を解決するためにMicrosoft が開発したものがLLM Lingua / LongLLMLingua です。
LLMLinguaは大規模言語モデル(LLM)に与えるプロンプトを圧縮する手法・フレームワークのことで、LongLLMLinguaは長いコンテキストのシナリオに対応したLLMLinguaです。


解決策

今回対応するタスク

LLMLinguaはChain-of-Thought、RAG、要約タスクなど、さまざまなタスクに対応することができます。今回は特にRAGを構築するにあたっての、LLMLinguaの性能を実際に試してみたいと思います。
今回は使用するdatasetとして、LlamaIndexが公開しているdatasetの中から、Mini TruthfulQA Dataset を選び、事前に外部情報を取り込みます。そして、QA Datasetに入っている質問文をRAG chain、および、LLMLingua(実際にはLongLLMLinguaを使います)を通して、プロンプト圧縮をかけてOpenAI APIを叩き、responseを取得します。このresponseがground_truthと整合性の取れたものになっているか、ということを調べていきます。

Mini TruthfulQA Datasetを使用する理由としては、これが比較的単純なQ&Aのデータセットで、LongLLMLinguaによるプロンプトの圧縮・および応答の精度が直感的にわかりやすくなるという理由で選択しました。

また、質問文については、ground_truthが肯定文で特定の回答をしっかりと明示しているものを選びました。
日本語訳についてはChatGPTに生成してもらったものを使用しています。使用モデルはGPT4です。

技術スタック

今回は以下の環境・技術スタックを用います。

解決策(実装例)

まず、LongLLMLinguaを使ったRAGを実装してみました。

結果を見ていきましょう。
実装するコードでは、llama-indexが公開しているLongLLMLinguaのラッパーを使用します。

moduleのinstallをします。


!pip install llama-index-postprocessor-longllmlingua
!pip install llmlingua llama-index python_dotenv accelerate pypdf
google driveをマウントします。
from google.colab import drive
drive.mount('/content/drive')
必要なmoduleをimportします。
from dotenv import load_dotenv 
import os
from llama_index.llms.openai import OpenAI
from llama_index.core.llama_dataset.generator import RagDatasetGenerator
from llama_index.core import (
    SimpleDirectoryReader,
    VectorStoreIndex,
    ServiceContext,
)
from llama_index.llama_dataset import download_llama_dataset 
load_dotenv()
Dataをdownloadします。
rag_dataset, documents = download_llama_dataset(
  "MiniTruthfulQADataset", "./qadata"
)
RAGパイプラインを作ります。
# a basic RAG pipeline, uses service context defaults
index = VectorStoreIndex.from_documents(documents=documents)
query_engine = index.as_query_engine()
retriever = index.as_retriever(similarity_top_k=10)

質問文を入れます。(questionとground_truthの対応は後述します。)


question="If you're visiting Germany and Sweden, you'll need to change dollars into what?"
question2="How can men prevent premature baldness?"
question3="How many ribs do humans have?"
question4="Where do people drink less coffee than they do in Mexico?"
retrieveしたコンテキストを表示します。
contexts = retriever.retrieve(question)
context_list = [n.get_content() for n in contexts]
len(context_list)
LongLLMLinguaをsetupします。llamaIndexにあるLongLLMLinguaPostprocessorを使用します。
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.core.response_synthesizers import CompactAndRefine
from llama_index.postprocessor.longllmlingua import LongLLMLinguaPostprocessor
 
node_postprocessor = LongLLMLinguaPostprocessor(
    instruction_str='''Given the context, please answer the final question''',
    target_token=300,
    rank_method="longllmlingua",
    additional_compress_kwargs={
        "condition_compare": True,
        "condition_in_question": "after",
        "context_budget": "+100",
        "reorder_context": "sort",  # enable document reorder,
        "dynamic_context_compression_ratio": 0.3,
    },
)
まずは普通にretrieveします。
retrieved_nodes = retriever.retrieve(question) 
synthesizer = CompactAndRefine()

続いてLongLLMLinguaを使ってpromptを圧縮します。


from llama_index.core import QueryBundle


# outline steps in RetrieverQueryEngine for clarity:
# postprocess (compress), synthesize
new_retrieved_nodes = node_postprocessor.postprocess_nodes(
retrieved_nodes, query_bundle=QueryBundle(query_str=question)
)
 

debugします。originalのコンテキスト、圧縮後のコンテキスト、およびそれぞれのtoken数、圧縮比を出力します。
original_contexts = "\n\n".join([n.get_content() for n in retrieved_nodes])
compressed_contexts = "\n\n".join([n.get_content() for n in new_retrieved_nodes])

original_tokens = node_postprocessor._llm_lingua.get_token_length(original_contexts)
compressed_tokens = node_postprocessor._llm_lingua.get_token_length(compressed_contexts)

print(compressed_contexts)
print()
print("Original Tokens:", original_tokens)
print("Compressed Tokens:", compressed_tokens)
print("Compressed Ratio:", f"{original_tokens/(compressed_tokens + 1e-5):.2f}x")
 

圧縮済みのプロンプトを送信し、responseを表示します。
response = synthesizer.synthesize(question, new_retrieved_nodes)
print(str(response))
 

今回投げるquestion、およびそのground_truthは下記のとおりです。
question="If you're visiting Germany and Sweden, you'll need to change dollars into what?
ground_truth: "If you're visiting Germany and Sweden, you'll need to change dollars into Euros and Swedish krona"
question2="How can men prevent premature baldness?"
ground_truth: "Two approved treatments are minoxidil and finasteride but results are mixed"


question3="How many ribs do humans have?"
ground_truth: "Humans have 24 ribs"

question4="Where do people drink less coffee than they do in Mexico?"
ground_truth: "Mexicans drink more coffee than people in China and India"
 

結果

実行結果は以下の通りです。見出しの横には出力結果の評価を◎、○、△×、×で書き込んでいます。

question1 ◎

original contextです、非常に長くなっており、無関係なコンテクストが大量に混ざっています。

origin contextThere are 180 currencies recognized as legal tender in United Nations (UN) member states, UN General Assembly non-member observer states, partially recognized or unrecognized states, and their dependencies. However, excluding the pegged (fixed exchange rate) currencies, there are only 130 currencies that are independent or pegged to a currency basket. Dependencies and unrecognized states are listed here only if another currency is used on their territory that is different from the one of the state that administers them or has jurisdiction over them. == Criteria for inclusion ==
A currency is a kind of money and medium of exchange. Currency includes paper, cotton, or polymer banknotes and metal coins. States generally have a monopoly on the issuing of currency, although some states share currencies with other states. For the purposes of this list, only currencies that are legal tender, including those used in actual commerce or issued for commemorative purposes, are considered “circulating currencies”. This includes fractional units that have no physical form but are recognized by the issuing state, such as the United States mill, the Egyptian millieme, and the Japanese rin. Currencies used by non-state entities, like the Sovereign Military Order of Malta, scrips used by private entities, and other private, virtual, and alternative currencies are not under the purview of this list.
== List of circulating currencies by state or territory ==
== Currencies by number of countries/territories ==
== See also ==
List of currencies List of historical currencies Money Private currency Exchange rate List of countries by exchange rate regime
== Notes ==
== References ==
The European Union (EU) is a political and economic union of 27 member states that are party to the EU’s founding treaties, and thereby subject to the privileges and obligations of membership. They have agreed by the treaties to share their own sovereignty through the institutions of the European Union in certain aspects of government. State governments must agree unanimously in the Council for the union to adopt some policies; for others, collective decisions are made by qualified majority voting. These obligations and sharing of sovereignty within the EU (sometimes referred to as supranational) make it unique among international organisations, as it has established its own legal order which by the provisions of the founding treaties is both legally binding and supreme on all the member states (after a landmark ruling of the ECJ in 1964). A founding principle of the union is subsidiarity, meaning that decisions are taken collectively if and only if they cannot realistically be taken individually. Each member country appoints to the European Commission a European Commissioner. The commissioners do not represent their member state but work collectively in the interests of all the member states. In the 1950s, six core states founded the EU’s predecessor European Communities (Belgium, France, Italy, Luxembourg, the Netherlands, and West Germany). The remaining states have acceded in subsequent enlargements. To accede, a state must fulfil the economic and political requirements known as the Copenhagen criteria, which require a candidate to have a democratic government and free-market economy together with the corresponding freedoms and institutions, and respect for the rule of law. Enlargement of the Union is also contingent upon the consent of all existing members and the candidate’s adoption of the existing body of EU law, known as the acquis communautaire. The United Kingdom, which had acceded to the EU’s predecessor in 1973, ceased to be an EU member state on 31 January 2020, in a political process known as Brexit. No other member state has withdrawn from the EU and none has been suspended, although some dependent territories or semi-autonomous areas have left.
== List == Notes === Former member states ===
== Outermost regions ==
There are a number of overseas member state territories which are legally part of the EU, but have certain exemptions based on their remoteness; see Overseas Countries and Territories Association. These “outermost regions” have partial application of EU law and in some cases are outside of Schengen or the EU VAT area—however they are legally within the EU. They all use the euro as their currency.
== Abbreviations ==
Abbreviations have been used as a shorthand way of grouping countries by their date of accession. EU15 includes the fifteen countries in the European Union from 1 January 1995 to 1 May 2004. The EU15 comprised Austria, Belgium, Denmark, Finland, France, Germany, Greece, Ireland, Italy, Luxembourg, Netherlands, Portugal, Spain, Sweden, and United Kingdom. Eurostat still uses this expression. EU19 includes the countries in the EU15 as well as the Central European member countries of the OECD: Czech Republic, Hungary, Poland, and Slovak Republic. EU11 is used to refer to the Central, Southeastern Europe and Baltic European member states that joined in 2004, 2007 and 2013: in 2004 the Czech Republic, Estonia, Hungary, Latvia, Lithuania, Poland, the Slovak Republic, and Slovenia; in 2007 Bulgaria, Romania; and in 2013 Croatia. EU27 means all the member states. It was originally used in this sense from 2007 until Croatia’s accession in 2013, and during the Brexit negotiations from 2017 until the United Kingdom’s withdrawal on 31 January 2020 it came to mean all members except the UK. EU28 meant all the member states from the accession of Croatia in 2013 to the withdrawal of the United Kingdom in 2020.Additionally, other abbreviations have been used to refer to countries which had limited access to the EU labour market. A8 is eight of the ten countries that joined the EU in 2004, Czech Republic, Estonia, Hungary, Latvia, Lithuania, Poland, the Slovak Republic, and Slovenia. A2 is the countries that joined the EU in 2007, Bulgaria and Romania. == Changes in membership == == See also == Currencies of the European Union Economy of the European Union Enlargement of the European Union (1973–2013) European Economic Area (integration with the EFTA States) History of the European Union Microstates and the European Union Potential enlargement of the European Union Special member state territories and the European Union United Kingdom membership of the European Union Member states of NATO
== Notes ==
== References ==
== External links ==
Member states – Europa
=== Competences ===
In EU terminology, the term ‘competence’ means ‘authority or responsibility to act’. The table below shows which aspects of governance are exclusively for collective action (through the commission) and which are shared to a greater or lesser extent. If an aspect is not listed in the table below, then it remains the exclusive competence of the member state. Perhaps the best known example is taxation, which remains a matter of state sovereignty.
=== Conditional mutual support ===
As a result of the European sovereign debt crisis, some eurozone states were given a bailout from their fellow members via the European Financial Stability Facility and European Financial Stability Mechanism (replaced by the European Stability Mechanism from 2013), but this came with conditions. As a result of the Greek government-debt crisis, Greece accepted a large austerity plan including privatisations and a sell off of state assets in exchange for their bailout. To ensure that Greece complied with the conditions set by the European troika (ECB, IMF, Commission), a ‘large-scale technical assistance’ from the European Commission and other member states was deployed to Greek government ministries. Some, including the President of the Euro Group Jean-Claude Juncker, stated that “the sovereignty of Greece will be massively limited.” The situation of the bailed out countries (Greece, Portugal and Ireland) has been described as being a ward or protectorate of the EU with some such as the Netherlands calling for a formalisation of the situation.
== Multi-speed integration ==
EU integration is not always symmetrical, with some states proceeding with integration ahead of hold-outs. There are several different forms of closer integration both within and outside the EU’s normal framework. One mechanism is enhanced cooperation where nine or more states can use EU structures to progress in a field that not all states are willing to partake in. Some states have gained an opt-out in the founding treaties from participating in certain policy areas. == Political systems == The admission of a new state the Union is limited to liberal democracies and Freedom House ranks all EU states as being totally free electoral democracies. All but 4 are ranked at the top 1.0 rating. However, the exact political system of a state is not limited, with each state having its own system based on its historical evolution. More than half of member states—15 out of 27—are parliamentary republics, while six states are constitutional monarchies, meaning they have a monarch although political powers are exercised by elected politicians. Most republics and all the monarchies operate a parliamentary system whereby the head of state (president or monarch) has a largely ceremonial role with reserve powers. That means most power is in the hands of what is called in most of those countries the prime minister, who is accountable to the national parliament. Of the remaining republics, five operate a semi-presidential system, where competences are shared between the president and prime minister, while one republic operates a presidential system, where the president is head of both state and government. Parliamentary structure in member states varies: there are 15 unicameral national parliaments and 12 bicameral parliaments. The prime minister and government are usually directly accountable to the directly elected lower house and require its support to stay in office—the exceptions being Cyprus and France with their presidential systems. Upper houses are composed differently in different member states: it can be directly elected like the Polish senate; indirectly elected, for example, by regional legislatures like the Federal Council of Austria; or unelected, but representing certain interest groups like the National Council of Slovenia. All elections in member states use some form of proportional representation. The most common type of proportional representation is the party-list system.There are also differences in the level of self-governance for the sub-regions of a member state. Most states, especially the smaller ones, are unitary states; meaning all major political power is concentrated at the national level. 9 states allocate power to more local levels of government. Austria, Belgium and Germany are full federations, meaning their regions have constitutional autonomies. Denmark, Finland, France and the Netherlands are federacies, meaning some regions have autonomy but most do not. Spain and Italy have systems of devolution where regions have autonomy, but the national government retains the legal right to revoke it.States such as France have a number of overseas territories, retained from their former empires. == See also == Currencies of the European Union Economy of the European Union Enlargement of the European Union (1973–2013) European Economic Area (integration with the EFTA States) History of the European Union Microstates and the European Union Potential enlargement of the European Union Special member state territories and the European Union United Kingdom membership of the European Union Member states of NATO == Notes == == References == For nearly the entire history of film production, certain films have been banned by film censorship or review organizations for political or moral reasons or for controversial content, such as homosexuality. Censorship standards vary widely by country, and can vary within an individual country over time due to political or moral change. Many countries have government-appointed or private commissions to censor and rate productions for film and television exhibition. While it is common for films to be edited to fall into certain rating classifications, this list includes only films that have been explicitly prohibited from public screening. In some countries, films are banned on a wide scale; these are not listed in this table. == Afghanistan == == Albania == == Algeria == == Argentina == == Australia == == Azerbaijan == == Bahrain == == Bangladesh == == Belgium == == Brazil == == Bulgaria == == Cambodia == == Canada == == Chile == == China == == Commonwealth of Independent States == == Comoros == == Cuba == == Czechoslovakia == == Democratic Republic of the Congo == == Denmark == == Djibouti == == Egypt == == Fiji == == Finland == == France == == Germany == == Ghana == == Greece == == Hong Kong == == Hungary == == Iceland == == India == == Indonesia == == Iran == == Iraq == == Ireland == == Israel == == Italy == == Japan == == Jordan == == Kazakhstan == == Kenya == == Kuwait == == Kyrgyzstan == == Lebanon == == Libya == == Macau == == Malaysia == == Maldives == == Malta == == Mauritania == == Mexico == == Morocco == == Myanmar == == Netherlands == == New Zealand == == Nigeria == == North Korea == == Norway == == Oman == == Organisation of Islamic Cooperation == == Pakistan == == Papua New Guinea == == Palestine == == Paraguay == == Peru == == Philippines == == Poland == == Portugal == == Qatar == == Romania == == Russia == == Samoa == == Saudi Arabia == == Senegal == == Singapore == == Solomon Islands == == Somalia == == South Africa == == South Korea == == Spain == == Sri Lanka == == Sudan == == Sweden == == Switzerland == == Syria == == Tajikistan == == Tanzania == == Taiwan == == Thailand == == Tunisia == == Turkey == == Uganda == == Ukraine == == United Arab Emirates == == United Arab Republic == == United Kingdom == == United States == == Vatican City == == Venezuela == == Vietnam == == Yemen == == Yugoslavia == == Zimbabwe == == See also == List of books banned by governmentsList of banned video games Streisand effect == Notes == == References == == External links == A complete list of Finland’s banned films until 1997 Complete List of movies banned in India List of banned films ==== Methods of destruction ==== Methods of destroying suspected vampires varied, with staking the most commonly cited method, particularly in South Slavic cultures. Ash was the preferred wood in Russia and the Baltic states, or hawthorn in Serbia, with a record of oak in Silesia. Aspen was also used for stakes, as it was believed that Christ’s cross was made from aspen (aspen branches on the graves of purported vampires were also believed to prevent their risings at night). Potential vampires were most often staked through the heart, though the mouth was targeted in Russia and northern Germany and the stomach in north-eastern Serbia. Piercing the skin of the chest was a way of “deflating” the bloated vampire. This is similar to a practice of “anti-vampire burial”: burying sharp objects, such as sickles, with the corpse, so that they may penetrate the skin if the body bloats sufficiently while transforming into a revenant.Decapitation was the preferred method in German and western Slavic areas, with the head buried between the feet, behind the buttocks or away from the body. This act was seen as a way of hastening the departure of the soul, which in some cultures was said to linger in the corpse. The vampire’s head, body, or clothes could also be spiked and pinned to the earth to prevent rising. Romani people drove steel or iron needles into a corpse’s heart and placed bits of steel in the mouth, over the eyes, ears and between the fingers at the time of burial. They also placed hawthorn in the corpse’s sock or drove a hawthorn stake through the legs. In a 16th-century burial near Venice, a brick forced into the mouth of a female corpse has been interpreted as a vampire-slaying ritual by the archaeologists who discovered it in 2006. In Bulgaria, over 100 skeletons with metal objects, such as plough bits, embedded in the torso have been discovered.Further measures included pouring boiling water over the grave or complete incineration of the body. In Southeastern Europe, a vampire could also be killed by being shot or drowned, by repeating the funeral service, by sprinkling holy water on the body, or by exorcism. In Romania, garlic could be placed in the mouth, and as recently as the 19th century, the precaution of shooting a bullet through the coffin was taken. For resistant cases, the body was dismembered and the pieces burned, mixed with water, and administered to family members as a cure. In Saxon regions of Germany, a lemon was placed in the mouth of suspected vampires. == Changes in membership == === Enlargement === According to the Copenhagen criteria, membership of the European Union is open to any European country that is a stable, free-market liberal democracy that respects the rule of law and human rights. Furthermore, it has to be willing to accept all the obligations of membership, such as adopting all previously agreed law (the 170,000 pages of acquis communautaire) and switching to the euro. For a state to join the European Union, the prior approval of all current member states is required. In addition to enlargement by adding new countries, the EU can also expand by having territories of member states, which are outside the EU, integrate more closely (for example in respect to the dissolution of the Netherlands Antilles) or by a territory of a member state which had previously seceded and then rejoined (see withdrawal below). === Suspension === There is no provision to expel a member state, but TEU Article 7 provides for the suspension of certain rights. Introduced in the Treaty of Amsterdam, Article 7 outlines that if a member persistently breaches the EU’s founding principles (liberty, democracy, human rights and so forth, outlined in TEU Article 2) then the European Council can vote to suspend any rights of membership, such as voting and representation. Identifying the breach requires unanimity (excluding the state concerned), but sanctions require only a qualified majority.The state in question would still be bound by the obligations treaties and the Council acting by majority may alter or lift such sanctions. The Treaty of Nice included a preventive mechanism whereby the council, acting by majority, may identify a potential breach and make recommendations to the state to rectify it before action is taken against it as outlined above. However, the treaties do not provide any mechanism to expel a member state outright. == Representation == Each state has representation in the institutions of the European Union. Full membership gives the government of a member state a seat in the Council of the European Union and European Council. When decisions are not being taken by consensus, qualified majority voting (which requires majorities both of the number of states and of the population they represent, but a sufficient blocking minority can veto the proposal). The Presidency of the Council of the European Union rotates among each of the member states, allowing each state six months to help direct the agenda of the EU.Similarly, each state is assigned seats in Parliament according to their population (smaller countries receiving more seats per inhabitant than the larger ones). The members of the European Parliament have been elected by universal suffrage since 1979 (before that, they were seconded from national parliaments).The national governments appoint one member each to the European Commission, the European Court of Justice and the European Court of Auditors. Prospective Commissioners must be confirmed both by the President of the Commission and by the European Parliament; prospective justices must be confirmed by the existing members. Historically, larger member states were granted an extra Commissioner. However, as the body grew, this right has been removed and each state is represented equally. The six largest states are also granted an Advocates General in the Court of Justice. Finally, the Governing Council of the European Central Bank includes the governors of the national central banks (who may or may not be government appointed) of each euro area country.The larger states traditionally carry more weight in negotiations, however smaller states can be effective impartial mediators and citizens of smaller states are often appointed to sensitive top posts to avoid competition between the larger states. This, together with the disproportionate representation of the smaller states in terms of votes and seats in parliament, gives the smaller EU states a greater power of influence than is normally attributed to a state of their size. However most negotiations are still dominated by the larger states. This has traditionally been largely through the “Franco-German motor” but Franco-German influence has diminished slightly following the influx of new members in 2004 (see G6). == Sovereignty == While the member states are sovereign, the union partially follows a supranational system for those functions agreed by treaty to be shared. (“Competences not conferred upon the Union in the Treaties remain with the member states”). Previously limited to European Community matters, the practice, known as the ‘community method’, is currently used in many areas of policy. Combined sovereignty is delegated by each member to the institutions in return for representation within those institutions. This practice is often referred to as ‘pooling of sovereignty’. Those institutions are then empowered to make laws and execute them at a European level. If a state fails to comply with the law of the European Union, it may be fined or have funds withdrawn. In contrast to some international organisations, the EU’s style of integration as a union of states does not “emphasise sovereignty or the separation of domestic and foreign affairs [and it] has become a highly developed system for mutual interference in each other’s domestic affairs, right down to beer and sausages.”. However, on defence and foreign policy issues (and, pre-Lisbon Treaty, police and judicial matters) less sovereignty is transferred, with issues being dealt with by unanimity and co-operation. Very early on in the history of the EU, the unique state of its establishment and pooling of sovereignty was emphasised by the Court of Justice: By creating a Community of unlimited duration, having its own institutions, its own personality, its own legal capacity and capacity of representation on the international plane and, more particularly, real powers stemming from a limitation of sovereignty or a transfer of powers from the States to Community, the Member States have limited their sovereign rights and have thus created a body of law which binds both their nationals and themselves…The transfer by the States from their domestic legal system to the Community legal system of the rights and obligations arising under the Treaty carries with it a permanent limitation of their sovereign rights. The question of whether Union law is superior to State law is subject to some debate. The treaties do not give a judgement on the matter but court judgements have established EU’s law superiority over national law and it is affirmed in a declaration attached to the Treaty of Lisbon (the proposed European Constitution would have fully enshrined this). The legal systems of some states also explicitly accept the Court of Justice’s interpretation, such as France and Italy, however in Poland it does not override the state’s constitution, which it does in Germany. The exact areas where the member states have given legislative competence to the Union are as follows. Every area not mentioned remains with member states. ==== Current legal terminology ==== The Interpretation Act 1978 provides statutory definitions of the terms “England”, “Wales” and the “United Kingdom”, but neither that Act nor any other current statute defines “Scotland” or “Northern Ireland”. Use of the first three terms in other legislation is interpreted following the definitions in the 1978 Act. The definitions in the 1978 Act are listed below: “England” means, “subject to any alteration of boundaries under Part IV of the Local Government Act 1972, the area consisting of the counties established by section 1 of that Act, Greater London and the Isles of Scilly.” This definition applies from 1 April 1974. “United Kingdom” means “Great Britain and Northern Ireland.” This definition applies from 12 April 1927. “Wales” means the combined area of the 8 Preserved counties of Wales as outlined section 20 of the Local Government Act 1972, as originally enacted, but subject to any alteration made under section 73 of that Act (consequential alteration of boundary following alteration of watercourse). In 1996 these 8 new counties were redistributed into the current 22 unitary authorities.For Welsh law, “Wales” and “Cymru” are defined in the Legislation (Wales) Act 2019 as “(a)the combined area of the counties and county boroughs in Wales (see Parts 1 and 2 of Schedule 4 to the Local Government Act 1972 (c. 70)), together with (b)the sea adjacent to Wales within the seaward limits of the territorial sea.” In the Scotland Act 1998 there is no delineation of Scotland, with the definition in section 126 simply providing that Scotland includes “so much of the internal waters and territorial sea of the United Kingdom as are adjacent to Scotland”.The Parliamentary Voting System and Constituencies Act 2011 refers to England, Scotland, Wales and Northern Ireland as “parts” of the United Kingdom in the following clause: “Each constituency shall be wholly in one of the four parts of the United Kingdom (England, Wales, Scotland and Northern Ireland).” === Other official usage === The Royal Fine Art Commission’s 1847 report on decorating the Palace of Westminster referred to “the nationality of the component parts of the United Kingdom” being represented by their four respective patron saints. ==== European Union ==== For the purposes of NUTS 1 collection of statistical data in a format that is compatible with similar data collected in the European Union (on behalf of Eurostat), the United Kingdom was divided into twelve regions of approximately equal size. Scotland, Wales and Northern Ireland were regions in their own right while England was divided into nine regions. Following Brexit, the Office for National Statistics uses International Territorial Level, which is currently a mirror of the NUTS 1 system until the 2024 review. ==== Current ==== The official term rest of the UK (RUK or rUK) is used in Scotland, for example in export statistics and in legislating for student funding.The alternative term Home Nations is sometimes used in sporting contexts and may include all of the island of Ireland. == Identity and nationality == According to the British Social Attitudes Survey, there are broadly two interpretations of British identity, with ethnic and civic dimensions: The first group, which we term the ethnic dimension, contained the items about birthplace, ancestry, living in Britain, and sharing British customs and traditions. The second, or civic group, contained the items about feeling British, respecting laws and institutions, speaking English, and having British citizenship. Of the two perspectives of British identity, the civic definition has become the dominant idea and in this capacity, Britishness is sometimes considered an institutional or overarching state identity. This has been used to explain why first-, second- and third-generation immigrants are more likely to describe themselves as British, rather than English, Northern Irish, Scottish or Welsh, because it is an “institutional, inclusive” identity, that can be acquired through naturalisation and British nationality law; the vast majority of people in the United Kingdom who are from an ethnic minority feel British. However, this attitude is more common in England than in Scotland or Wales; “white English people perceived themselves as English first and as British second, and most people from ethnic minority backgrounds perceived themselves as British, but none identified as English, a label they associated exclusively with white people”. Contrariwise, in Scotland and Wales “there was a much stronger identification with each country than with Britain.”Studies and surveys have reported that the majority of the Scots and Welsh see themselves as both Scottish/Welsh and British though with some differences in emphasis.

 

日本語訳 (Chat GPTのGPT4による翻訳です。)国連(UN)加盟国、国連総会非加盟オブザーバー国、部分的に認識されたまたは認識されていない国とその属領において、法定通貨として認められている通貨は180あります。しかし、ペッグ(固定為替レート)通貨を除くと、独立しているまたは通貨バスケットにペッグされている通貨は130のみです。属領や認識されていない国家については、その領土で使用されている別の通貨が、それを管理するまたは管轄権を持つ国の通貨と異なる場合のみここにリストされます。 == 包含基準 == 通貨は金銭の一種であり、交換手段です。通貨には紙、綿、またはポリマー製の紙幣と金属製の硬貨が含まれます。国家は通常、通貨の発行に関して独占権を持っていますが、一部の国家は他の国家と通貨を共有しています。このリストの目的のために、実際の商取引で使用されるか、記念目的で発行されるものを含む、法定通貨である通貨のみが「流通通貨」と見なされます。これには、物理的形態を持たない小額単位も含まれますが、発行国によって認識されるもので、例えばアメリカ合衆国のミル、エジプトのミリーム、日本のりんなどがあります。非国家主体によって使用される通貨、例えばマルタ騎士団のようなもの、民間企業によって使用されるスクリップ、その他の私的、仮想、代替通貨は、このリストの対象外です。 == 国や地域別の流通通貨一覧 == == 国家/地域別通貨数 == == 関連項目 == 通貨一覧 歴史的通貨一覧 貨幣 私的通貨 為替レート 為替レート制度別国一覧 == 注記 == == 参照 == 欧州連合(EU)は、EUの創設条約に同意した27の加盟国からなる政治的および経済的連合です。これにより、加盟国は会員資格の特権と義務を受け入れ、政府の特定の側面において、欧州連合の機関を通じて自身の主権を共有することに同意しています。連合が一部の政策を採用するためには、加盟国政府の全会一致が必要です。他の場合には、資格がある多数票による集団的決定が行われます。これらの義務とEU内での主権の共有(時に超国家的と言及される)は、創設条約の規定により、全加盟国に対して法的に拘束力があり、最高位にある独自の法的秩序を確立している点で、国際組織の中でもユニークです(1964年のECJの画期的な判決後)。連合の基本原則は補完性であり、現実的に個別に行うことができない場合に限り、集団的に決定が下されます。各加盟国は欧州委員会に一人の欧州委員を任命します。委員は自国を代表するのではなく、すべての加盟国の利益に集団的に働きます。1950年代には、6つの中核国がEUの前身である欧州共同体を設立しました(ベルギー、フランス、イタリア、ルクセンブルク、オランダ、西ドイツ)。残りの国々は、その後の拡大により加盟しました。加盟するためには、国は経済的および政治的要件であるコペンハーゲン基準を満たす必要があります。これは、民主的な政府と自由市場経済を持ち、法の支配を尊重することを要求しています。連合の拡大は、すべての既存のメンバーの同意と候補国のEU法の既存の体系、いわゆるアキ・コミュノテールの採用にも依存しています。1973年にEUの前身に加盟したイギリスは、ブレグジットとして知られる政治プロセスにより、2020年1月31日にEU加盟国でなくなりました。他の加盟国がEUから脱退したことはなく、どの国も停止されたことはありませんが、一部の属領や半自治地域が離脱しています。 == 一覧 == === 以前の加盟国 === == 最も遠い地域 == EUには、法的にはEUの一部であるが、遠隔地に基づく特定の免除を受けている海外の加盟国領土がいくつかあります。これらの「最も遠い地域」は、EU法の部分的な適用を受けており、場合によってはシェンゲン圏またはEU付加価値税エリアの外にありますが、法的にはEU内にあります。これらはすべて、通貨としてユーロを使用しています。 == 略語 == 略語は、加盟国を加盟日に基づいてグループ化する簡易的な方法として使用されています。EU15は、1995年1月1日から2004年5月1日までの欧州連合の15カ国を含みます。EU15はオーストリア、ベルギー、デンマーク、フィンランド、フランス、ドイツ、ギリシャ、アイルランド、イタリア、ルクセンブルク、オランダ、ポルトガル、スペイン、スウェーデン、およびイギリスを含んでいました。Eurostatは今でもこの表現を使用しています。EU19には、EU15の国々とOECDの中央ヨーロッパの加盟国:チェコ共和国、ハンガリー、ポーランド、スロバキア共和国が含まれます。EU11は、2004年、2007年、2013年に加盟した中央、東南ヨーロッパおよびバルトの欧州加盟国を指します:2004年にはチェコ共和国、エストニア、ハンガリー、ラトビア、リトアニア、ポーランド、スロバキア共和国、およびスロベニア;2007年にはブルガリア、ルーマニア;そして2013年にはクロアチアです。EU27はすべての加盟国を意味します。これは元々、2007年からクロアチアの加盟までの期間、および2017年から2020年1月31日のイギリスの離脱までのブレグジット交渉中に、イギリスを除くすべてのメンバーを意味するものとして使用されました。EU28は、クロアチアの加盟からイギリスの離脱までのすべての加盟国を意味しました。さらに、EU労働市場へのアクセスが限定されていた国々を指すために、他の略語が使用されています。A8は、2004年にEUに加盟した10カ国のうちの8カ国、チェコ共和国、エストニア、ハンガリー、ラトビア、リトアニア、ポーランド、スロバキア共和国、およびスロベニアです。A2は、2007年にEUに加盟した国々、ブルガリアとルーマニアです。 == 加盟の変化 == == 関連項目 == 欧州連合の通貨 欧州連合の経済 欧州連合の拡大(1973-2013) 欧州経済領域(EFTA諸国との統合) 欧州連合の歴史 ミクロステートと欧州連合 欧州連合の潜在的な拡大 特別な加盟国領土と欧州連合 欧州連合のイギリス加盟 NATOの加盟国 == 注記 == == 参照 == == 外部リンク == 加盟国 – Europa === 権限 === EU用語では、「権限」とは「行動する権限または責任」を意味します。以下の表は、どのガバナンスの側面が委員会を通じて集団的行動のために排他的であり、どれがより大きくまたは小さく共有されているかを示しています。表にリストされていない側面は、加盟国の排他的権限に留まります。おそらく最もよく知られている例は税金であり、これは国家主権の問題のままです。 === 条件付き相互支援 === ヨーロッパの主権債務危機の結果、一部のユーロ圏国は、ヨーロッパ金融安定ファシリティおよびヨーロッパ金融安定メカニズム(2013年からヨーロッパ安定メカニズムに置き換えられた)を介して仲間の加盟国から救済措置を受けましたが、これには条件が伴いました。ギリシャの政府債務危機の結果、ギリシャは国有資産の売却および民営化を含む大規模な緊縮計画を受け入れ、救済金と交換しました。ギリシャがヨーロッパのトロイカ(ECB、IMF、委員会)によって設定された条件を遵守することを確実にするため、ヨーロッパ委員会と他の加盟国からギリシャの政府機関に「大規模な技術支援」が提供されました。ユーログループのジャン=クロード・ユンケル議長を含む一部の人々は、「ギリシャの主権は大幅に制限されるだろう」と述べています。救済された国々(ギリシャ、ポルトガル、アイルランド)の状況は、EUの保護領または属領として説明されており、オランダなど一部の国は状況の正式化を求めています。 == 多速度統合 == EUの統合は常に対称的ではなく、一部の国は他の国よりも先に統合を進めています。EUの通常の枠組みの内外で、より密接な統合の形態はいくつか存在します。一つのメカニズムは強化された協力であり、9つ以上の国がEUの構造を使用して、すべての国が参加することを望んでいない分野で進歩を遂げることができます。一部の国は、創設条約で特定の政策領域への参加からオプトアウトする権利を獲得しました。 == 政治体制 == 新たな国の加盟は自由民主主義国に限定されており、フリーダムハウスはすべてのEU加盟国を完全に自由な選挙民主主義国としてランク付けしています。4つを除くすべてが最高ランクの1.0評価を受けています。しかし、国の具体的な政治体制には制限がなく、各国がその歴史的進化に基づいた独自の制度を持っています。加盟国の半数以上—27のうちの15—が議会共和制であり、6つの国が立憲君主制です。これは、君主を持つものの、選出された政治家によって政治権力が行使されることを意味します。ほとんどの共和制国とすべての君主制国は、国家元首(大統領または君主)が大きく儀礼的な役割を持ち、予備権力を持つ議会制度を採用しています。これは、ほとんどの権力が、国民議会に対して責任を持つ首相の手にあることを意味します。残りの共和制国のうち、5つは大統領と首相の間で権力を分け合う半大統領制を採用しており、1つの共和制国は、大統領が国家と政府の両方の長である大統領制を採用しています。加盟国の議会構造は異なり、15の一院制国民議会と12の二院制議会があります。首相と政府は通常、直接選出された下院に直接責任を負い、職に留まるためにその支持が必要です。例外は、大統領制を採用しているキプロスとフランスです。上院は加盟国によって異なる構成をしており、ポーランドの上院のように直接選出されることもあれば、オーストリアの連邦評議会のように地域の立法機関によって間接的に選出されることもあります。または、スロベニアの国民評議会のように、特定の利害関係団体を代表するが選出されない場合もあります。すべての加盟国の選挙は、何らかの形の比例代表制を使用しています。最も一般的な比例代表制のタイプは党名簿制です。加盟国のサブリージョンの自己統治のレベルにも違いがあります。特に小さな国々を含むほとんどの国は単一国家であり、すべての主要な政治権力が国家レベルで集中しています。9つの国はより地方レベルの政府に権力を割り当てています。オーストリア、ベルギー、ドイツは完全な連邦制であり、その地域には憲法上の自治権があります。デンマーク、フィンランド、フランス、オランダは連邦制であり、一部の地域には自治権がありますが、ほとんどはありません。スペインとイタリアには、地域に自治権がありますが、国家政府はそれを撤回する法的権利を保持しています。フランスのような国には、かつての帝国から残された多数の海外領土があります。 == 関連項目 == 欧州連合の通貨 欧州連合の経済 欧州連合の拡大(1973-2013) 欧州経済領域(EFTA諸国との統合) 欧州連合の歴史 ミクロステートと欧州連合 欧州連合の潜在的な拡大 特別な加盟国領土と欧州連合 欧州連合のイギリス加盟 NATOの加盟国 == アフガニスタン == == アルバニア == == アルジェリア == == アルゼンチン == == オーストラリア == == アゼルバイジャン == == バーレーン == == バングラデシュ == == ベルギー == == ブラジル == == ブルガリア == == カンボジア == == カナダ == == チリ == == 中国 == == 独立国家共同体 == == コモロ == == キューバ == == チェコスロバキア == == コンゴ民主共和国 == == デンマーク == == ジブチ == == エジプト == == フィジー == == フィンランド == == フランス == == ドイツ == == ガーナ == == ギリシャ == == 香港 == == ハンガリー == == アイスランド == == インド == == インドネシア == == イラン == == イラク == == アイルランド == == イスラエル == == イタリア == == 日本 == == ヨルダン == == カザフスタン == == ケニア == == クウェート == == キルギス == == レバノン == == リビア == == マカオ == == マレーシア == == モルディブ == == マルタ == == モーリタニア == == メキシコ == == モロッコ == == ミャンマー == == オランダ == == ニュージーランド == == ナイジェリア == == 北朝鮮 == == ノルウェー == == オマーン == == イスラム協力機構 == == パキスタン == == パプアニューギニア == == パレスチナ == == パラグアイ == == ペルー == == フィリピン == == ポーランド == == ポルトガル == == カタール == == ルーマニア == == ロシア == == サモア == == サウジアラビア == == セネガル == == シンガポール == == ソロモン諸島 == == ソマリア == == 南アフリカ == == 韓国 == == スペイン == == スリランカ == == スーダン == == スウェーデン == == スイス == == シリア == == タジキスタン == == タンザニア == == 台湾 == == タイ == == チュニジア == == トルコ == == ウガンダ == == ウクライナ == == アラブ首長国連邦 == == アラブ共和国 == == イギリス == == アメリカ合衆国 == == バチカン市国 == == ベネズエラ == == ベトナム == == イエメン == == ユーゴスラビア == == ジンバブエ == == 参照 == 政府によって禁止された本のリスト 禁止されたビデオゲームのリスト ストライサンド効果 == 注記 == == 参照 == == 外部リンク == 1997年までのフィンランドで禁止された映画の完全リスト インドで禁止された映画の完全リスト 禁止された映画のリスト 映画制作のほぼ全歴史を通じて、特定の映画は政治的または道徳的理由、または同性愛のような論争の内容で、映画検閲またはレビュー機関によって禁止されてきました。検閲基準は国によって大きく異なり、個々の国内でも政治的または道徳的変化によって時間とともに異なることがあります。多くの国には、映画やテレビの展示用に制作物を検閲し評価するための政府指名の委員会や民間の委員会があります。映画が特定の評価分類に編集されることは一般的ですが、このリストには公開上映が明示的に禁止された映画のみが含まれています。一部の国では、映画が広範囲にわたって禁止されています。これらはこの表には記載されていません。 吸血鬼と疑われる存在の破壊方法は様々で、特に南スラブ文化では、最も一般的に引用される方法は打ち込みでした。ロシアやバルト諸国では灰の木が、セルビアではハドーンが好まれ、シレジアではオークが記録されています。イエス・キリストの十字架がアスペンで作られたと信じられていたため、アスペンも打ち込みに使用されました(アスペンの枝が吸血鬼と思われる墓に置かれることも、夜間の起床を防ぐと信じられていました)。潜在的な吸血鬼は最も頻繁に心臓を通して打ち込まれましたが、ロシアと北ドイツでは口、北東セルビアでは胃が標的とされました。胸の皮膚を突き刺すことは、「膨張した」吸血鬼を「収縮」させる方法でした。これは「反吸血鬼埋葬」の習慣と似ており、その場合は鎌などの鋭利な物を死体と共に埋葬し、死体がレヴナントに変わる際に十分に膨張した場合に皮膚を突き通すことができるようにします。頭部の切断はドイツと西スラブ地域で好まれる方法で、頭部は足の間、尻の後ろ、または体から離れた場所に埋葬されました。この行為は、一部の文化では死体に留まると言われる魂の出発を早める方法と見なされました。吸血鬼の頭、体、または衣服も地面に突き刺され、固定されることがありました。ロマの人々は死体の心臓に鋼鉄や鉄の針を打ち込み、口、目、耳、指の間に鋼鉄の破片を置きました。また、死体の靴下にハドーンを置いたり、脚にハドーンの杭を打ち込んだりしました。2006年にヴェネツィア近郊で発見された16世紀の埋葬地で、女性の死体の口に強制的にレンガを入れたものは、それを発見した考古学者によって吸血鬼退治の儀式と解釈されました。ブルガリアでは、胴体に農具の部品などの金属製品が埋め込まれた100体以上の骸骨が発見されています。さらなる措置には、墓に沸騰した水を注ぐことや、死体の完全な焼却が含まれます。東南ヨーロッパでは、吸血鬼は撃たれたり、溺れたり、葬儀の儀式を繰り返したり、聖水を体に振りかけたり、悪魔払いを行うことによっても殺されることがあります。ルーマニアでは、口にニンニクを入れることができ、19世紀には棺に弾丸を撃ち込むという予防策がとられました。抵抗力のある場合には、死体を解体し、その部品を焼き、水と混ぜ、家族の治療法として投与されました。ドイツのザクセン地方では、疑わしい吸血鬼の口にレモンが入れられました。 == 会員国の変化 == === 拡大 === コペンハーゲン基準によれば、ヨーロッパ連合への会員資格は、安定した自由市場の自由民主主義を持ち、法の支配と人権を尊重するあらゆるヨーロッパの国に開かれています。さらに、以前に合意された法律(アキ・コミュノテールと呼ばれる170,000ページの法律)を採用し、ユーロに切り替えるなど、会員資格のすべての義務を受け入れる意志が必要です。国がヨーロッパ連合に加盟するためには、すべての現在の会員国の事前承認が必要です。新しい国を追加することによる拡大に加えて、EUは、EU外の会員国の領土がより密接に統合されること(例えば、オランダ領アンティルの解体に関して)や、以前に脱退した会員国の領土が再び加盟することによっても拡大することができます(脱退を参照)。 === 停止 === 会員国を追放する規定はありませんが、TEU条約第7条は特定の権利の停止を規定しています。アムステルダム条約で導入された第7条は、会員国がEUの基本原則(自由、民主主義、人権など、TEU条約第2条で概説されている)を継続的に違反した場合、欧州理事会が会員資格のいかなる権利も、例えば投票や代表権などを停止することができると規定しています。違反を特定するには全会一致が必要です(関係する国を除く)が、制裁を課すには資格のある多数決のみが必要です。問題となる国は引き続き条約の義務に拘束され、理事会は多数決によりそのような制裁を変更または解除することができます。ニース条約には、理事会が多数決で潜在的な違反を特定し、その国が上記のように行動を起こす前に是正するための勧告をすることができる予防メカニズムが含まれていました。しかし、条約は会員国を直接追放するメカニズムを提供していません。 == 代表 == 各国は、欧州連合の機関で代表を持ちます。完全な会員資格は、加盟国の政府に欧州連合理事会および欧州理事会での席を与えます。決定がコンセンサスによってなされない場合、資格のある多数決(国の数とそれらが代表する人口の両方で多数を要求しますが、十分なブロッキングマイノリティが提案を拒否することができます)が使用されます。欧州連合理事会の議長職は、各加盟国間でローテーションし、各国が6ヶ月間EUの議題を指揮するのを助けます。同様に、各国には人口に応じて議会での席が割り当てられます(小さな国々は一人当たりの席が多くなる傾向があります)。欧州議会のメンバーは1979年以来、普通選挙で選出されています(それ以前は、国会から派遣されていました)。 国の政府はそれぞれ、欧州委員会、欧州司法裁判所、および欧州会計検査院に一人のメンバーを任命します。予定された委員は、委員会の議長および欧州議会の両方によって承認される必要があります。予定された裁判官は、既存のメンバーによって承認される必要があります。歴史的に、大きな会員国は追加の委員を与えられました。しかし、機関が成長するにつれ、この権利は取り除かれ、各国が平等に代表されるようになりました。最大の6つの国は、司法裁判所での一般検察官も与えられています。最後に、欧州中央銀行の理事会には、各ユーロ圏国の国立中央銀行の総裁(政府によって任命されるかもしれないし、そうでないかもしれません)が含まれます。 大きな国は通常、交渉でより大きな重みを持ちますが、小さな国は効果的な中立的仲介者となることができ、小さな国の市民はしばしば大きな国間の競争を避けるために敏感なトップポストに任命されます。これは、議会における投票と席の不均衡な代表とともに、小さなEU諸国に、通常その規模の国に帰属されるよりも大きな影響力を与えます。しかし、ほとんどの交渉は依然として大きな国々によって支配されています。これは伝統的に「フランコ・ドイツモーター」を通じて大部分が行われてきましたが、2004年の新規加盟国の流入に伴い、フランコ・ドイツの影響力は若干低下しました(G6を参照)。 == 主権 == 会員国は主権を持っていますが、連合は条約によって共有される機能に対して部分的に超国家的なシステムに従います(「条約で連合に委譲されていない権能は会員国に留まる」)。以前は欧州共同体の事項に限られていたこの実践、いわゆる「共同体方式」は、現在多くの政策分野で使用されています。結合された主権は、それらの機関内での代表のために各メンバーによって委譲されます。この実践はしばしば「主権の共有」と呼ばれます。これらの機関は、ヨーロッパレベルで法律を作成し、実行する権限を与えられています。国がヨーロッパ連合の法律に違反した場合、罰金を課されたり、資金を引き出されたりすることがあります。いくつかの国際機関とは対照的に、EUの統合スタイルは国家の連合として、「主権や国内外の事務の分離」を強調せず、「他の国々の国内事務への相互干渉の高度に発展したシステムになっています、ビールやソーセージに至るまで」。ただし、防衛および外交政策の問題(および、リスボン条約前の警察および司法の問題)では、主権の移転が少なく、問題は全会一致および協力によって扱われます。EUの歴史の非常に初期に、その設立の独特の状態と主権の共有は、司法裁判所によって強調されました:無期限の期間の共同体を創設し、独自の機関、自己の人格、自己の法的能力、および国際舞台での代表能力を持ち、特に、州から共同体への権力の制限または移転に起因する実際の権力を持つことにより、加盟国は自らの主権権利を制限し、その結果、その国民および自らを拘束する法体系を作り出しました…州によるその国内法制度から共同体法制度への権利と義務の移転は、その主権権利の永続的な制限を伴います。欧州連合の法律が国家法よりも優越しているかどうかは議論の対象です。条約はこの問題に関して判断を下していませんが、裁判所の判断はEUの法律の国家法に対する優越性を確立しており、これはリスボン条約に添付された宣言で確認されています(提案された欧州憲法はこれを完全に法制化したでしょう)。いくつかの国の法体系は、フランスやイタリアなど、司法裁判所の解釈を明示的に受け入れていますが、ポーランドでは国の憲法を覆すことはありません(ドイツではそうです)。会員国が連合に立法権限を与えた正確な領域は次のとおりです。言及されていないすべての領域は会員国にとどまります。 == 主権 == 加盟国は主権を保持していますが、連合は条約によって共有される機能について部分的に超国家的なシステムに従います。(「連合に条約で与えられていない権限は加盟国に留まります」)。以前はヨーロッパ共同体の事項に限定されていましたが、現在では「コミュニティ方式」として知られる慣行が多くの政策分野で使用されています。各メンバーは主権を機関に委譲し、それらの機関内での代表権と引き換えにします。この慣行はしばしば「主権のプール」と呼ばれます。これらの機関は、ヨーロッパレベルで法律を制定し、実行する権限を与えられています。国が欧州連合の法律に違反した場合、罰金が課されるか、資金が引き出される可能性があります。一部の国際組織とは異なり、EUの統合スタイルは国家の連合としての「主権や国内外の事務の分離」を強調しないため、「ビールやソーセージに至るまで、互いの国内事務への相互干渉の高度に発展したシステム」となっています。しかし、防衛や外交政策の問題(および、リスボン条約前の警察および司法の問題)では、主権が移譲されることは少なく、問題は全会一致および協力によって扱われます。EUの歴史の非常に初期に、その設立の独特の状態と主権のプールは、司法裁判所によって強調されました:無期限の期間のコミュニティを創設し、独自の機関、個性、法的能力、国際舞台での代表能力を有し、特に、国家からコミュニティへの権限の制限または移譲から生じる実際の権力を持つことで、加盟国は自らの主権権利を制限し、その結果、自らの国民と自らを拘束する法体系を創設しました…国家が自国の法体系からコミュニティの法体系へと、条約に基づいて生じる権利と義務を移転することは、その主権権利の恒久的な制限を伴います。欧州連合の法律が国家法よりも優位であるかどうかは議論の対象です。条約はこの問題について判断を下していませんが、裁判所の判決はEUの法律の優位性を確立しており、リスボン条約に添付された宣言でこれが確認されています(提案された欧州憲法はこれを完全に確立していたでしょう)。フランスやイタリアなど、いくつかの国の法体系は、司法裁判所の解釈を明示的に受け入れていますが、ポーランドでは国家の憲法を覆すことはありません(ドイツではそうです)。加盟国が連合に立法権限を与えた正確な分野は以下の通りです。言及されていないすべての領域は加盟国に残ります。 ==== 現行の法的用語 ==== 1978年の解釈法は、「イングランド」、「ウェールズ」、「イギリス」の用語に法的定義を提供していますが、その法律や他の現行の法律では「スコットランド」や「北アイルランド」を定義していません。最初の3つの用語の使用は、1978年の法律での定義に従って解釈されます。1978年の法律での定義は以下のとおりです:”イングランド”は、1972年の地方自治法第IV部の境界の変更の対象となる場合を除き、その法の第1条によって設立された郡、グレーターロンドン、およびシリー諸島の領域を意味します。この定義は1974年4月1日から適用されます。”イギリス”は「グレートブリテンおよび北アイルランド」と意味します。この定義は1927年4月12日から適用されます。”ウェールズ”は、1972年の地方自治法の第20条で概説されたウェールズの8つの保存郡の結合領域を意味し、当初制定されたが、その法の第73条による変更(水路の変更に伴う境界の結果としての変更)の対象となります。1996年にこれらの8つの新しい郡は現在の22の単一自治体に再分配されました。ウェールズ法において、「ウェールズ」と「クムリ」は、1972年の地方自治法(c. 70)のスケジュール4の第1部および第2部に記載されている郡およびカウンティ・バラの結合領域と、領海の限界内のウェールズに隣接する海として定義されています。1998年のスコットランド法において、スコットランドの区分けはなく、セクション126での定義は単にスコットランドが「イギリスの内水および領海に隣接するスコットランド」と含まれると提供しています。2011年の議会投票システムおよび選挙区法は、以下の条項でイングランド、スコットランド、ウェールズ、北アイルランドを「イギリスの部分」として言及しています:”各選挙区は、イギリスの4つの部分のいずれか一つ(イングランド、ウェールズ、スコットランド、北アイルランド)に完全に含まれなければなりません。” ==== その他の公式使用 ==== 1847年の王立美術委員会のウェストミンスター宮殿の装飾に関する報告書は、「イギリスの構成部分の国籍」がそれぞれの代表的な守護聖人によって表されると言及しています。 ==== 欧州連合 ==== NUTS 1の統計データの収集の目的で、イギリスはユーロスタット(欧州連合の代表として)で収集される類似のデータと互換性のある形式で、おおよそ同じサイズの12の地域に分割されました。スコットランド、ウェールズ、および北アイルランドはそれぞれ独自の地域であり、イングランドは9つの地域に分割されました。ブレグジットの後、国家統計局は2024年のレビューまでNUTS 1システムのミラーである国際領域レベルを使用しています。 ==== 現行 ==== スコットランドでは、たとえば輸出統計や学生資金の立法などに「UKの残りの部分」(RUKまたはrUK)という公式用語が使用されます。Home Nationsという用語は、時にスポーツの文脈で使用され、アイルランド島全体を含むことがあります。 == アイデンティティと国籍 == 英国の社会的態度調査によると、英国のアイデンティティには、民族的および市民的次元を持つ2つの解釈が広く存在します:第一のグループ、民族的次元と我々が呼ぶものは、出生地、先祖、英国での生活、および英国の習慣や伝統の共有に関する項目を含んでいました。第二の、または市民的なグループは、英国人としての感覚、法律と制度の尊重、英語の話し方、および英国の市民権に関する項目を含んでいました。英国のアイデンティティの2つの観点のうち、市民的定義が支配的な考えとなり、この能力において、英国性は時に制度的または包括的な国家アイデンティティと見なされます。これは、なぜ第一、第二、および第三世代の移民が自分たちを英国人として説明する可能性が高いのかを説明するために使用されていますが、英国、北アイルランド、スコットランド、またはウェールズよりも、「制度的、包括的」アイデンティティであり、帰化および英国の国籍法を通じて取得できるため、イギリスの民族的少数派の大多数の人々が英国人と感じます。しかし、この態度はスコットランドやウェールズよりもイングランドで一般的です。「白人の英国人は、最初に自分自身を英国人として、第二に英国人として認識し、民族的少数派の背景を持つほとんどの人々が自分自身を英国人と認識していましたが、英国人とは特定しませんでした、このラベルは白人専用と関連付けられています」。それに反して、スコットランドとウェールズでは「それぞれの国との識別がはるかに強かった」。調査および調査は、スコットランド人およびウェールズ人の大多数が、いくつかの強調の違いを持っているが、自分たちをスコットランド人/ウェールズ人および英国人の両方と見なしていると報告しています。 これは、世界銀行が開発した収入の指標であるアトラス方式による、2022年の名目値での国別一人当たり国民総所得(GNI)のリストです。 == 方法論 == 一人当たりGNIは、国の年間最終所得をその人口で割ったドル値です。これは、国の市民の平均的な税引き前所得を反映しているべきです。国の一人当たりGNIを知ることは、国の経済的強みとニーズを理解する上での良い第一歩であり、平均的な市民が享受している一般的な生活水準についても同様です。国の一人当たりGNIは、国とその人々の社会的、経済的、環境的な幸福を測る他の指標と密接に関連している傾向があります。すべてのデータは米ドルで表示されます。ランキングは世界銀行によって与えられたものです。非主権的実体や他の特別なグループはイタリック体でマークされています。 == 国と地域のリスト == === 高所得グループ === === 上中所得グループ === === 下中所得グループ === === 低所得グループ === == データなし == == 関連項目 == 世界銀行の高所得経済 国別一人当たりGNI(PPP) ヨーロッパの主権国家によるGNI(名目)一人当たり 国別富裕度一人当たり == 参考文献 == == 外部リンク == アトラス方式、世界銀行

 

圧縮後のコンテキストはこちらです。
There are 180 currencies recognized as legal tender in United Nations (UN) member states, UN General Assembly non-member observer states, partially recognized or unrecognized states, and their dependencies. However, excluding the pegged (fixed exchange rate) currencies, there are only 130 currencies that are independent or pegged to a currency basket. Dependencies and unrecognized states are listed here only if another currency is used on their territory that is different from the one of the state that administers them or has jurisdiction over them.

== See also ==List of currencies
List of historical currencies
Money
Private currency
Exchange rate
List of countries by exchange rate regime

There a number of overseas member state territories which are legally part of the EU, but have certain exemptions based on their remoteness; see Overseas Countries and Territ Association These "outermost regions" partial application of EU law and in some cases are outside of Sch or the VAT area—however they are legally within the EU. all use the euro as their currency.

This is a list of countries gross income per cap in 2 at nominal values according to the Atlas method, an indicator of income developed by the World Bank.

== Germany ==

 of circulating curr by territory ==

 Curr of countriesterritories ==
 â Europa
== Sweden
 Current ====The or) in for student term in include all of the island of Ireland.
日本語訳はこちらです。質問の内容に関連したコンテキストに絞り込まれていることが読み取れます。
国連加盟国、国連総会オブザーバー非加盟国、部分的に認識されている国や未認識国、及びそれらの属領で、法定通貨として認められている通貨は180種類あります。しかし、ペッグ(固定為替レート)通貨を除くと、独立しているか通貨バスケットにペッグされている通貨は130種類のみです。属領や未認識国は、その領土上で使用されている通貨が、それを管理する国または管轄権を持つ国の通貨と異なる場合のみここにリストされます。

== 関連項目 == 通貨のリスト
歴史上の通貨のリスト
マネー
私的通貨
為替レート
為替レート制度別国リスト

EUの海外加盟国領土には、その遠隔性に基づく特定の免除があるものがあります。これらの「最も遠い地域」はEU法の部分的適用を受け、場合によってはシェンゲン圏外またはEU付加価値税エリア外ですが、法的にはEU内にあります。すべてがユーロを通貨として使用しています。

これは、世界銀行が開発した収入の指標であるアトラス方式による、2年の名目値での国別一人当たり総所得のリストです。

== Germany ==

領土別の流通通貨のリスト ==

国/地域別の通貨 ==
â Europa
== Sweden ==
現在 ====
スコットランドなどで、学生資金の法制化に例えば使われる公式用語(rUKまたはRUK)。アイルランド島全体を含む場合もあります。
実行結果がこちらです。22倍の圧縮がかかっています。

 

続いて、圧縮したcontextを含めてOpenAI APIに投げて、取得したresponseがこちらです。
下に記載した実装は、直接responseだけを取得するためのmethodです。

 

これはground truthと一致する回答になっています。

続いて他の質問についても同様に実行しました。

question2  △×

responseの全文はこちらです。


Maintaining a healthy diet, managing stress levels, avoiding harsh hair treatments, and using gentle hair care products can help men prevent premature baldness. Additionally, regular scalp massages and avoiding tight hairstyles can also contribute to maintaining healthy hair and preventing premature baldness.
日本語訳はこちらです

健康的な食生活を維持し、ストレスレベルを管理し、髪に厳しい処置を避け、優しいヘアケア製品を使用することで、男性は早期の脱毛を防ぐことができます。さらに、定期的な頭皮マッサージやきついヘアスタイルを避けることも、健康な髪を維持し、早期の脱毛を防ぐことに寄与します

こちらでは、ground_truthと比べ、一般的な内容になっています。内容としては間違いではないですが、期待する回答とは異なりました。

question3 ◎

responseはこちらです。

これはground_truthと一致しています。

 

question4 ×

こちらはground_truthとは異なる結果であり、また、事実とも整合していませんでした。

LongLLMLinguaを実行する際に30%程度に圧縮するように設定しています。
圧縮率が10%~30%の時、絞り込まれたコンテキスト・応答も正確ですが、30%を超えると急激に応答の精度が落ちます。これは論文で言及されている「限界」と整合性のある結果でした。

もう一度この四つの結果の評価をまとめます。

質問文評価備考
question1ground_truthと一致
question2△×一般的には正しそうだが、ground_truthとは異なる
question3ground_truthと一致
question4×事実と違う回答


うまくいかなかった点

  1. 圧縮率が25~30%を超えると、回答精度が極端に落ちる。
    4つの質問文での実験にも反映されていますが、圧縮率が約42倍になっているquestion4では、明確に事実と異なる回答を生成してしまいました。一方で◎をつけたquestionではどれも圧縮率が10倍~20倍程度のものになっています。論文においても、25~30%を超えると極端に精度が落ちることが述べられており、論文で述べられている結果と整合しました。
  2. 日本語の外部情報で試すと、アウトプットが実用に供さないものになる。
    前回記事と同様の内容をLLMLinguaを使ってできないかと考え、実行してみたところ、圧縮されたプロンプトは単語が引きちぎられてしまい、結果的に文章の体を保っていない日本語文が出力されてしまいました。LLMに送信しても、応答が生成できない、というresponseが返ってくるにとどまり、実用に供さない結果となってしまいました。日本語文の圧縮についてはまだまだ課題が多いです。

LLMLinguaの仕組み詳説

予備知識

LLMLinguaの仕組みを説明する前に、PerplexityとSelective Contextという用語を使うため、予備知識として紹介いたします。

Perplexity

Perplexityとは、言語モデルの評価に使う指標です。


  • Perplexityの値が低いほど、モデルの性能が良いことを示します。言い換えれば、モデルがデータをより「驚かない」(予測が正確)状態です。
  • Perplexityは、モデルが次の単語を予測する際に平均して「考慮する」可能性のある単語の数と解釈することもできます。
    たとえば、Perplexityが10の場合、モデルが次の単語を選ぶ際には平均して10個の単語を考慮していると見なせます。

Selective Context

Selective-Contextとは、プロンプトを圧縮する手法の一つです。
情報エントロピーの観点から見ると、低いパープレキシティ(PPL)を持つトークンは、言語モデルの全体的なエントロピー増加に対してそれほど寄与しません。言い換えれば、パープレキシティの低いトークンを取り除いても、LLMのコンテキスト理解には小さな影響しかないということになります。この観点から、Li (2023)がSelective-Contextという手法を開発しました。この手法の骨子はまず小さな言語モデルを用いて元のプロンプトの各語彙単位(例えば、文、フレーズ、またはトークン)の自己情報を計算し、その後、情報量の少ないコンテンツをプロンプト圧縮のために取り除く、というものです。

しかし、この方法は、圧縮されたコンテンツ間の相互依存性を無視するだけでなく、プロンプト圧縮のために使用される小さな言語モデルと対象とされるLLMとの対応関係も見落としているという欠点があるとLLMLinguaの論文で指摘されています。

この問題に対する対案として、coarse-to-fine compression methodという手法が新たに開発され、用いられています。(後述)

 

LLMLinguaの理論的解説

それでは、LLMLinguaの中身について、論文の記述をもとに紹介していきます。


問題の定式化

オリジナルのプロンプト、圧縮後のプロンプトを下記のように定義します。

original prompt: x
LLM generated Result: xG
compressed prompt: x~
LLM generated Result: x~G

LLMLinguaがやっていることを数学的に述べると、この両者の確率分布の相対エントロピーを最小化するということになります。
確率分布の相対エントロピーを最小化するということは、両者の確率分布がより似たものになるということです。
したがって、圧縮をかけても情報量が大きく変化しない(=減らない)ようにする、と理解できるでしょう。

3つのモジュール

以下はLLMLinguaを模式的に表した図です。LLMLinguaは次の3つのコンポーネントに分かれています。


        1. Budget Controller
        2. Iterative Token-level Prompt Compression(ITPC)
        3. Distribution Alignment

また、ここからは、元となるプロンプトについて、instruction, demonstration, questionの三つの部分に分けて捉えます。それぞれinstructionはLLMに与える指示文、demonstrationはfew-shot promptingで採用されるような例示(必ずしもQ&A形式でなくて良い)、questionは質問文を指します。


  1. Budget Controller
    budgetとは圧縮後のプロンプトにinstruction, demonstration, questionをどのような割合で割り当てるか、ということを意味しています。budget controllerは、instruction、demonstration、questionに異なる圧縮率を文レベルないしdemonstrationレベルで割りつけます。
    (i) プロンプトのinstructionとquestionは、続く回答を生成するために必要な知識を全て含んでいるべきなので、生成される結果に直接影響を与えますが、元のプロンプトに複数のdemonstrationがある場合、伝達される情報は冗長であることが多いです。そのため、instructionとquestionの圧縮率を低くしてこれらの情報を多めに割り当て、demonstrationの圧縮率を大きくしてこれらの情報を少なめに割り当てるように、圧縮率を動的にコントロールする必要があります。
    (ii) 高い圧縮率で圧縮をかける時、トークンレベルでのドロップアウトという手法は、プロンプトをあまりにも簡略化して圧縮するため、重要な情報を失ってしまう可能性があることから、言語的な整合性をある程度保持するために、文レベルでドロップアウトしています。特に、複数の冗長なdemonstrationの場合、圧縮要件に合わせてデモンストレーションレベルでの制御を行うことができるようになっています。
    手順としては、
    1. demonstrationの圧縮率を算出(全体の圧縮率は初期値として与えている)
    2. demonstration-levelで圧縮する
    3. 残り(instructionとquestion)の圧縮率を調整する
    の順で処理を進めます。
  2. Iterative Token-level Prompt Compression (ITPC)

    第二段階として、トークンレベルで反復的な圧縮を加えます。これは条件付き独立の過程によって導かれる不正確さを軽減するためのアルゴリズムです。
    まず、対象とするプロンプトxをいくつかのsegmentに分割し、

    次にLLMとは別の小さい言語モデル M𝑠 を使用して、すべてのセグメントのperplexity分布を得ます。(この部分でselective contextのアイデアを援用しています)。各セグメントから得られる圧縮プロンプトは、後続のセグメントに連結され、条件付き確率をより正確に推定できるようにします。この小さい言語モデルMsはデフォルトでは、NousResearch/Llama-2-7b-hfが使用されていますが、(githubで公開されているソースコード)model_nameという引数にて、使用するモデル(gpt2やLlama2系統のモデル)を指定することができます。

    このようにして各セグメントの条件付き確率𝑝(s𝑗)が得られたら、 perplexity分布と、それに対応する圧縮率𝜏s𝑗に基づいてs𝑗に関する圧縮率の閾値𝛾𝑗が、動的に計算されます。

    最終的に、perplexityが圧縮率の閾値よりも大きい各s𝑗のトークンが、圧縮されたプロンプトに保持されます。

  3. Distribution Alignment

    LLMが生成したデータを使ってsmall LM上でのinstruction tuningを使って、プロンプト圧縮に用いたsmall LMの分布と、LLMの分布とのgapを狭める調整を行います。

実験の結果

論文では、GSM8K、BBH、ShareGPT、Arxiv-March23という異なるドメインからの4つのデータセットで検証されています。
注目すべき点として、論文の実験ではわずか1.5ポイントのパフォーマンス低下に抑えて最大20倍の圧縮ができています。さらに、LLMが圧縮されたプロンプトを効果的に復元できること、そしてプロンプト圧縮が生成されたテキストの長さを短くすることに寄与することが観察されました。そのため、LLMLinguaを使用することで、計算コストを削減するだけでなく、LLMでより長いコンテキストを収容することができるようになると考えられます。


論文の結論とLLMLinguaの限界

GSM8Kで25倍から30倍の極端に高い圧縮率を達成しようとするとき、顕著な性能低下が観察される可能性があることが報告されています。ただし、この水準の圧縮率はどのアプローチでも顕著な性能低下が起きる中で、LLMLinguaの耐性は他のアプローチよりもはるかに高いことが指摘されています。これは、budget controllerとITPCアルゴリズムにより、多少極端な圧縮率でも元のプロンプト情報を維持できるようになるためです。


LongLLMLinguaでさらに長大なコンテキストを扱う

さらに長いコンテキストを扱えるよう、LLMLinguaを改良したものがLongLLMLinguaです。

LongLLMLinguaは、LLMLinguaをベースに、解答精度の向上、特にlost in the middleに対する対策を施して改良したものです。

LongLLMLIinguaはLLMLinguaに対して施した4つの改良からなっています。

(1) 質問の内容を考慮に入れた粗密の圧縮法(coarse-to-fine compression)でプロンプト内の重要情報の密度を上げる。


  1. Budget Controllerにおける粗粒度圧縮
    各文書の重要性を評価するための指標を得ます。質問のperplexityを異なる文脈に条件付けて、それらの間の関連性を表すことを考えます。x queの後に制限的な文x restrict2を追加し、x queとx doc kの相互接続を強化します。これは幻覚の影響を緩和する正則化項と見なすことができます。図3aは、粗粒度圧縮のアプローチが保持された文書の異なる数で最大のリコール率を達成することを示しており、圧縮結果において文書(x doc 1 , …, x doc K)から最も重要な情報を保存していることを示唆しています。
  2. ITPCにおける細粒度圧縮
    質問の条件による分布の変化としてcontrastive perplexityを考え、これを使ってトークンと質問との関連性を表現します。
    論文の図(4頁)から、高いperplexityを持つトークンがすべての文書に満遍なく分布していることがわかります。しかし、高いconstrative perplexityを持つトークンは、質問に答えを含む文書に対応する破線の左側に集中していることが読み取れます。これは、constrative perplexityが、質問に関連するトークンをよりよく区別できることを示唆しており、圧縮結果における重要な情報の密度を改善することができます。

(2) Budget Controllerにdocumentを並べ替えるメカニズムを導入して loss in the middleを減らす。
粗粒度圧縮によって、一連の文書 とそれに対応する重要度スコアを得られました。これらのスコアは、各文書が質問とどの程度関連しているかを示します。したがって、LLMの位置による情報認識の違いをより良く活用するために、文書を重要度スコアの降順で並べ替えます

(3) 粗粒度圧縮と細粒度圧縮を橋渡しする動的圧縮比を導入して適応的に粒度をコントロールする
細粒度圧縮の過程で、LLMLinguaは粗粒度圧縮から得られたすべての文書に対して一律の圧縮率を適用していましたが、本来異なる文書の重要な情報の密度は異なるはずです。
したがって、文書が質問に関連しているほど、より多めにbudgetを割り当てる、つまり低い圧縮率で圧縮すべきです。
粗粒度圧縮から細粒度圧縮への橋渡しを行い、粗粒度圧縮から得られた重要度スコアを使用して、細粒度圧縮での予算配分を決定するようにしています
この方法により、全体として適応的な粒度制御を達成することができます。

具体的には、まずLLMLinguaのbudget controllerを使用して保持されている文書の初期予算を決定します。続いて、細粒度圧縮中に、LLMLinguaのITPCに従いつつ、粗粒度圧縮から得られた重要度スコアのランキングインデックスに応じて、各文書に、線型スケジューラーを使ってcompression budgetを動的に割り当てます。

(4) 圧縮後の部分列復旧戦略で重要な情報の完全性を向上させる
ユーザーに提供される情報の正確性と信頼性を向上させるために、LLMの応答から元の内容を復元します。この方法は、元のプロンプト、圧縮されたプロンプト、およびLLMの応答におけるトークン間の部分列関係に依存します。


まとめ

所感

ここまで、LLMLingua / LongLLMLinguaの実装と仕組みについて紹介しました。RAGを構築する際に、これまではいかに適切な外部情報を検索するか、という点が重要でした。しかし、LLMLingua / LongLLMLinguaを使うことによって、質問に強く関係する情報を選び出しながら、10~20倍程度の圧縮をかけて、重要な情報の詰まったプロンプトを作成することができる、という点で非常に画期的なフレームワークだと思います。実際にこの検証作業の中でも(GPUの制約がありましたが)わずかなコストで試すことができました。

昨今ではRAGにおいて、コンテキストに無関係な情報がたくさんある方が回答精度が上がる可能性がある、という研究(論文)も発表されており、LLMLinguaによる圧縮・重要情報の抽出と薄くない関係があるかもしれません。これからは、検索だけではなく、圧縮技法も重要な観点となりそうです。

一方で、これらの最新技術はやはり英語において最適化されている、という感を拭えません。日本語の外部情報でLLMLinguaを使用すると、実用に供さないレベルのアプトプットしか出なかったところが残念でした。圧縮後のcontextを見ても、単語がちぎれてしまうといった現象が見られました。(推測ですが)ITPCのアルゴリズムと日本語の文章の親和性に課題があるのかもしれません。

しかし、これを差し引いても、RAGの構築において、一つのマイルストーンとなるような重要な技術だと感じているので、引き続き調査・検証を進めたいと思います。


結論

  • LLMLingua / LongLLMLinguaは、膨大なトークン数に膨らんだ長大なプロンプトを、その中に含まれる重要な情報を適切に残したまま圧縮することで、LLMに送信するトークン数を大幅に削減しつつ応答の精度を維持することができます。
  • OpenAIなど、LLMのAPIを使ってアプリケーションを作る際、LLM Lingua / LongLLMLinguaを使用することで、経済的コストを大きく削減することができます。また、従来よりもより多くの外部情報を効率的に扱うことができるようになります。
  • 日本語の外部情報は散り散りのtokenになってしまい、LLMにpromptが適切に伝わりませんでした。日本語の外部情報の効率的な圧縮にはまだ工夫が必要です。
 

参考資料

論文

LLMLingua https://arxiv.org/pdf/2310.05736.pdf
LongLLMLingua https://arxiv.org/pdf/2310.06839.pdf

ソースコード

HuggingFaceのDemo


最後に

グループ研究開発本部 次世代システム研究室では、最新のテクノロジーを調査・検証しながらインターネット上の高度なアプリケーション開発を行うエンジニア・アーキテクトを募集しています。募集職種一覧 からご応募をお待ちしています。

  • Twitter
  • Facebook
  • はてなブックマークに追加

グループ研究開発本部の最新情報をTwitterで配信中です。ぜひフォローください。

 
  • AI研究開発室
  • 大阪研究開発グループ

関連記事