alphaFeedback

WorksComputer Science

A Conditional Mutual Information Analysis of Response Variety in Language Models

AI contributions
Not recorded for this paper
View details

Abstract

Large language models provide a variety of responses at inference (generation) that conventionally depend on a temperature parameter. Using a conditional mutual information approach, a quantitative, entropy based analysis of response variety is given. Three limiting behaviors are defined: arbiter, independent (conditionally) and neutral (deterministic) that span no to maximal mutual information. We give examples of each behavior and suggest their application to: temperature analysis, language analysis, prompt compression, and knowledge graphs.

Introduction

Large language models (LLMs), with their autoregressive character, dominate text generation. Based on a “temperature” parameter, LLMs in inference/generative mode may provide a variety of responses to a given prompt. This work provides an analysis method of the variety of responses to a given prompt. It is more expressive than simply setting a temperature. The basis is a conditional version of mutual information [Cover]:

I(K1,K2∣Q)=Ep(q)Iq(K1,K2∣Q=q)=Ep(q)Ep(k1,k2∣q)log⁡[p(K1,K2∣Q)p(K1∣Q)p(K2∣Q)](1)I(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q)=E_{p(q)}I_q(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)=E_{p(q)}E_{p(\mathbf{k}^{1},\mathbf{k}^{2}\mid q)}\log\left[\frac{p(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q)}{p(\mathbf{K}^{1}\mid Q)p(\mathbf{K}^{2}\mid Q)}\right] \tag*{(1)}

with the operational expression

Iq(K1,K2∣Q=q):=∑k1∑k2p(k1,k2∣q)log⁡[p(k1,k2∣q)p(k1∣q)p(k2∣q)](2)I_q(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q):=\sum_{\mathbf{k}^{1}}\sum_{\mathbf{k}^{2}}p(\mathbf{k}^{1},\mathbf{k}^{2}\mid q)\log\left[\frac{p(\mathbf{k}^{1},\mathbf{k}^{2}\mid q)}{p(\mathbf{k}^{1}\mid q)p(\mathbf{k}^{2}\mid q)}\right] \tag*{(2)}

In eq:1.1, K1\mathbf{K}^{1} and K2\mathbf{K}^{2} are phrases that pre- and post-pend QQ; the latter thought of as a query, q∈Qq\in Q.

We shall show that

0≤I(K1,K2∣Q)≤min⁡[H(K1∣Q),H(K2∣Q)]≤H(X)(K1,K2,Q∈X)(3)0 \le I(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q) \le\min\left[H(\mathbf{K}^{1}\mid Q),H(\mathbf{K}^{2}\mid Q)\right] \le H(X)\quad(\mathbf{K}^{1},\mathbf{K}^{2},Q\in X) \tag*{(3)}

with H(X)H(X) the entropy of the vocabulary.

Without the conditionality, Eq. (1.1) simplifies to the standard mutual information (MI) between the probability of two correlated random variables (RVs) and their product, independent probabilities. Cover and Thomas’ book [Cover] also provides the conditional mutual information (CMI) version in Eq. (1.1) and various rewritings of it are used to obtain Eq. (3) and to analyze its limiting behaviors. When the CMI is maximum, one learns the most possible about K2\mathbf{K}^{2} from knowledge of K1\mathbf{K}^{1} (and vice versa), conditional on Q=qQ=q. When zero, no added information about K2\mathbf{K}^{2} due to knowledge of K1\mathbf{K}^{1} (and vice versa), conditional on query Q=qQ=q is obtained. Based on these limits, we define three instructive classes termed: arbiter, independent (conditionally) and neutral/deterministic. Examples of each class and their application to the four topics: 1) “temperature” analysis, 2) language analysis, 3) prompt compression and 4) knowledge graphs are presented.

Derivations

General Expressions

The following relies on Cover and Thomas’ book [Cover]. For notational simplicity, use “1”, “2” and “3” for the RV names. The conditional MI in Eq. (1.1.a), by expansion of numerator and denominator, is

I(1∣2)=H(1∣2)−H(1∣23)(4)I(1\mid2)=H(1\mid2)-H(1\mid23) \tag*{(4)}

in terms of the corresponding entropies.

Use the entropy decomposition expression

H(123)=H(1∣23)+H(2∣3)+H(3),(5)H(123)=H(1\mid23)+H(2\mid3)+H(3), \tag*{(5)}

written for −H(1∣23)-H(1\mid23), in Eq. (4) to get

I(13∣2)=H(1∣2)+H(2∣3)+H(3)−H(123).(6)I(13\mid2)=H(1\mid2)+H(2\mid3)+H(3)-H(123). \tag*{(6)}

Now use another version of H(123)H(123):

H(123)=H(12∣3)+H(3).(7)H(123)=H(12\mid3)+H(3). \tag*{(7)}

Substitute Eq. (7) in Eq. (6) to eliminate H(3)H(3):

I(13∣2)=H(1∣2)+H(2∣3)+H(3)−[H(12∣3)+H(3)]∴I(13∣2)=H(1∣2)+H(2∣3)−H(12∣3)(8)\begin{aligned} I(13\mid2)&=H(1\mid2)+H(2\mid3)+H(3)-\left[H(12\mid3)+H(3)\right]\\ &\therefore I(13\mid2)=H(1\mid2)+H(2\mid3)-H(12\mid3) \tag*{(8)} \end{aligned}

From Eq. (4),

I(13∣2)≤H(1∣2).(9)I(13\mid2)\le H(1\mid2). \tag*{(9)}

From Eq. (8),

I(13∣2)≤H(1∣2)+H(3∣2).(10)I(13\mid2)\le H(1\mid2)+H(3\mid2). \tag*{(10)}

Eq. (9) provides a tighter bound than that from Eq. (10).

From the ‘symmetry’ of Eq. (9),

I(13∣2)≤min⁡[H(1∣2),H(3∣2)]□.(11)I(13\mid2)\le\min\left[H(1\mid2),H(3\mid2)\right]\square. \tag*{(11)}

Limiting Cases

Various limiting behaviors are instructive. Throughout, assume that functional relations between given RVs are one-to-one, as is sensible for tokens.

Suppose 1=f(3)1=f(3). Then H(1∣23)→1=f(3)0H(1\mid23)\xrightarrow{1=f(3)}0 because there can be only one value of RV 1 for a specified value of RV 3. Thus, from Eq. (4)

I(13∣2)→1=f(3)H(1∣2)□.(12)I(13\mid2)\xrightarrow{1=f(3)}H(1\mid2)\square. \tag*{(12)}

Eq. (12) maximizes Eq. (11). Note that for any vocabulary it is straightforward to evaluate the conditional entropy H(1∣2)H(1\mid2).

Suppose 3=f(2)3=f(2). Then H(1∣23)→3=f(2)H(1∣2)H(1\mid23)\xrightarrow{3=f(2)}H(1\mid2) because RV 3 provides no added information about RV 2, given a value of RV 2. From Eq. (4)

I(13∣2)=H(1∣2)−H(1∣23)→3=f(2)H(1∣2)−H(1∣2)=0□.(13)I(13\mid2)=H(1\mid2)-H(1\mid23)\xrightarrow{3=f(2)}H(1\mid2)-H(1\mid2)=0\square. \tag*{(13)}

Lastly, as conditioning can only reduce entropy, Eq. (11) has the further limiting behavior that if e.g., the minimum in Eq. (11) is H(1∣2)H(1\mid2) then

I(1,3∣2)≤H(1∣2)≤H(1)□.(14)I(1,3\mid2) \le H(1\mid2) \le H(1) \square. \tag*{(14)}

Explicit proofs of the above two limiting cases are provided in Appendix § 6.

Limit Behavior and Terminology

With the above limit behaviors, three situations: arbiter, independent (conditionally) and neutral/deterministic can be inferred.

From Eq. (12), where 1=f(3)1=f(3), using the terminology and notation of the Introduction,

1) arbiter: I(K1,K2∣Q) →K1=f(K2) H(K1∣Q)≤H(K1)=H(X)(15)1)\ \text{arbiter:}\ I(\mathrm{K}^{1},\mathrm{K}^{2}\mid Q)\ \xrightarrow[\mathrm{K}^{1}=f(\mathrm{K}^{2})]{}\ H(\mathrm{K}^{1}\mid Q)\le H(\mathrm{K}^{1})=H(\mathrm{X}) \tag*{(15)}

where {K1,K2,Q}∈X\{\mathrm{K}^{1},\mathrm{K}^{2},Q\}\in\mathrm{X}, with X\mathrm{X} the token set of entropy H(X)H(\mathrm{X}). Here, one can conclude that, for a set of query words, there is a strong chance that for K1\mathrm{K}^{1} you “know” what K2\mathrm{K}^{2} is. Examples are given in Table 1.

K1\mathrm{K}^{1}K2\mathrm{K}^{2}Q=qQ=q
the black catover the moonjumped
peanut butterjellyand
breadbutterand
peachescreamand
Iyoulove
loveallconquers

Table 1. Arbiter examples.

This circumstance should be more likely for longer phrases, such as poetry/lyrics.

Regarding the inequality in Eq. (15), note that for many queries there will be {K1}\{\mathrm{K}^{1}\} sets where there is no correlation with a qq. E.g., q=[and]q=[\text{and}] with K1\mathrm{K}^{1} just about any word, such as {bread, milk, cat, ....} →\to [and]. For these qq’s, Iq(K1,K2∣Q=q)→H(K1)I_q(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)\to H(\mathbf{K}^{1}), the maximum possible entropy, which is the entropy of the vocabulary, as Q=K=V=X\mathbf{Q}=\mathbf{K}=\mathbf{V}=\mathbf{X}.

  1. Independent (conditionally): I(K1,K2∣Q=q)=0I(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)=0. (2.13)

Independence results from Eq. (1.1) when p(K1,K2∣Q=q)=p(K1∣Q=q)p(K2∣Q=q)p(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)=p(\mathbf{K}^{1}\mid Q=q)p(\mathbf{K}^{2}\mid Q=q) where, by definition, K2\mathbf{K}^{2} is uninformative about K1\mathbf{K}^{1}. Examples, with representation (K1)→[Q=q]→(K2)(\mathbf{K}^{1})\to[Q=q]\to(\mathbf{K}^{2}), are:

(he, they, she,...) →\to [looked] →\to (up, down, sideways,...).

This should be a common occurrence.

  1. Neutral/deterministic: I(K1,K2∣Q=q)=0I(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)=0. (2.14)

This occurs when K2=f(Q=q)\mathbf{K}^{2}=f(Q=q), (or K1=f(Q=q)\mathbf{K}^{1}=f(Q=q)), where there is no correlation between prefix and suffix, conditional on a query. We refer to it as neutral as nothing is learned about K2\mathbf{K}^{2} when K1\mathbf{K}^{1} is determined by a query Q=qQ=q. We refer to it as deterministic because p(K2=k∣Q=q)=δk,k^p(\mathbf{K}^{2}=\mathbf{k}\mid Q=q)=\delta_{\mathbf{k},\hat{\mathbf{k}}} (or p(K1=k∣Q=q)=δk,k^p(\mathbf{K}^{1}=\mathbf{k}\mid Q=q)=\delta_{\mathbf{k},\hat{\mathbf{k}}}) with k^\hat{\mathbf{k}} a token. This case should also be a common occurrence. It is easy to distinguish between independent (conditionally) and neutral/deterministic where, in both cases I(K1,K2∣Q=q)=0I(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)=0, because for neutral/deterministic p(K2=k∣Q=q)=δk,k^p(\mathbf{K}^{2}=\mathbf{k}\mid Q=q)=\delta_{\mathbf{k},\hat{\mathbf{k}}} (or p(K1=k∣Q=q)=δk,k^p(\mathbf{K}^{1}=\mathbf{k}\mid Q=q)=\delta_{\mathbf{k},\hat{\mathbf{k}}}).

Examples of neutral/deterministic with pattern [Q=q]→(K2)[Q=q]\to(\mathbf{K}^{2}) are shown in Table 2. E.g., for [Carpe] →\to (Diem) – a fixed prefix for this query, [Carpe]. That is, there is only one K2\mathbf{K}^{2} for this Q=qQ=q.

[Q=q][Q=q](K2)(\mathbf{K}^{2})
CarpeDiem
chitchat
topsyturvy
sink orswim
relatedto

Table 2.

Table 2. neutral/deterministic examples.

Of course, the last example in Table 2 is not precise because, e.g., K2=(with)\mathbf{K}^{2} = (\text{with}) is also possible.

But the others are distinctly deterministic.

Uses

Four uses of this mutual information are discussed here:

  1. Temperature. Generically, the above analysis can be viewed as a more specific approach to “temperature (TT)”. In generative mode TT is used to span, for low TT, almost always the same response, to high TT, with a greater variety of responses. Tasks such as mathematical proofs are appropriate to low TT while poetry would be better served by a higher TT. (Other methods of producing a variety of responses such as “top-K” and “top-P” exist of course. [von Platen])

  1. Language analysis. E.g., for a “connector” (Q=qQ=q) word. If a connector, qq, is “and” then one expects Iq(K1,K2∣Q=q)>0I_q(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)>0 because of phrases such as: (bread) – [and] – (butter), (peaches) – [and] – (cream), (black) – [and] – (white), etc. On the other hand, good candidates for a connector where Iq(K1,K2∣Q=q)=0I_q(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q=q)=0 because of independence could be, for examples, (he/they/she/…) – [looked] – (up/down/sideways…).

  1. Prompt compression. Here, the arbiter I(K1,K2∣Q)=H(K1∣Q)≤H(K1)I(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q)=H(\mathbf{K}^{1}\mid Q)\leq H(\mathbf{K}^{1}) for K2=f(K1)\mathbf{K}^{2}=f(\mathbf{K}^{1}) of Eq. (15) is most appropriate. A large CMI implies you learn about K2\mathbf{K}^{2} from knowing K1\mathbf{K}^{1}; so, K1\mathbf{K}^{1} can be skipped (and vice versa). For example,

(A hurricane has been announced.) – [Therefore,] – (air traffic will be disrupted.)

This K2\mathbf{K}^{2} will, with more than random weight, be preceded by this K1\mathbf{K}^{1}. Phrases such as:

(black) –[and] –(white)

come up often in texts. The probabilities of such phrases are higher than random implying the arbiter situation.

  1. Knowledge Graphs. In the context of knowledge graphs (KGs), the association of nodes (entities) with keys, K1\mathbf{K}^{1} and K2\mathbf{K}^{2}, and edges (relationships) as queries, QQ, is warranted. KGs [Edge] have become important to the systematization of Retrieval Augmented Generation (RAG)

[Dalimunthe, Zhao], with ongoing efforts to improve prompt design in Large Language Model inference/generation. Knowledge graphs should also fit the arbiter category because what is desired is K1=f(K2)\mathbf{K}^{1}=f\left(\mathbf{K}^{2}\right) whereby I(K1,K2∣Q)=H(K1∣Q)=H(K2∣Q)I\left(\mathbf{K}^{1},\mathbf{K}^{2}\mid Q\right)=H\left(\mathbf{K}^{1}\mid Q\right)=H\left(\mathbf{K}^{2}\mid Q\right). In other words, maximum CMI because, if phrases K2\mathbf{K}^{2} and K1\mathbf{K}^{1} are correlated, there is a lot of mutual information, conditional on Q=qQ=q. For example, a relationship word such as q=[developed]q=[\mathrm{developed}] can show a strong connection between two keys as in: (Albert Einstein) →\rightarrow [developed] →\rightarrow (a theory of relativity), as further elaborated in [Dalimunthe]. Relationship words with large CMI (approximately the entropy of a key, conditional on a given query) should help create KGs in an objective manner.

Concluding Remarks

In this work, we develop a method to analyze the relationship among words and phrases based on the conditional mutual information expression given in Eq. (1.1). Various limits of it follow from the connection between the two keys, K1\mathbf{K}^{1} and K2\mathbf{K}^{2}, or between a key, K1\mathbf{K}^{1} or K2\mathbf{K}^{2}, and the query, Q=qQ=q. Expressing the conditional mutual information in terms of its constituent entropies provides various limiting expressions. From Eq. (12), it is straightforward, given a token set X\mathbf{X}, to evaluate e.g., H(K1∣Q=q)→H(X∣Q=x)H\left(\mathbf{K}^{1}\mid Q=q\right)\rightarrow H\left(\mathbf{X}\mid Q=x\right) because all tokens are from same alphabet. The non-negativity of this entropy provides strict bounds on the possible CMI values.

Three cases are defined: arbiter, independent (conditionally) and neutral/deterministic that achieve limiting behaviors of the conditional mutual information. They are applied to four tasks: “Temperature” analysis, language analysis, prompt compression, and knowledge graphs. The most interesting cases correspond to the arbiter situation where the CMI is close to the conditional entropy H(X∣Q=x)H\left(\mathbf{X}\mid Q=x\right) as it relies on a strong relationship between the keys. As shown, this should be quite useful for prompt compression and knowledge graph/Retrieval Augmented Generation (KG/RAG) purposes.

Finally, with reference to Eq. (1.1), a similar analysis can be conducted for I(Q,K1∣K2)I\left(Q,\mathbf{K}^{1}\mid\mathbf{K}^{2}\right) or I(Q,K2∣K1)I\left(Q,\mathbf{K}^{2}\mid\mathbf{K}^{1}\right). The only distinction is which RV is fixed.

Appendix A

Eqs. (12) and (13) follow from the definitions of mutual information and entropy.

For Eq. (12), where 1=f(3)1=f(3):

p(x1,x3∣x2)=1∣x1=f(x3)p(x3∣x2)p(x_1,x_3\mid x_2)=\left.1\right|_{x_1=f(x_3)}p(x_3\mid x_2)
I(x1,x3∣x2)=E[log⁡p(x1,x3∣x2)p(x1∣x2)p(x3∣x2)]=E[log⁡1∣x1=f(x3)p(x3∣x2)p(x1∣x2)p(x3∣x2)]=E[log⁡1∣x1=f(x3)p(x1∣x2)]=E[log⁡1p(f(x3)∣x2)]=E[log⁡1p(x1∣x2)]≔H(1∣2)(16)\begin{aligned} I(x_1,x_3\mid x_2)&=E\left[\log\frac{p(x_1,x_3\mid x_2)}{p(x_1\mid x_2)p(x_3\mid x_2)}\right] \\ &=E\left[\log\frac{\left.1\right|_{x_1=f(x_3)}p(x_3\mid x_2)}{p(x_1\mid x_2)p(x_3\mid x_2)}\right] \\ &=E\left[\log\frac{\left.1\right|_{x_1=f(x_3)}}{p(x_1\mid x_2)}\right] =E\left[\log\frac{1}{p(f(x_3)\mid x_2)}\right] =E\left[\log\frac{1}{p(x_1\mid x_2)}\right]\coloneqq H(1\mid2) \tag*{(16)} \end{aligned}

For Eq. (13), where 3=f(2)3=f(2):

H(1∣23)→−∑x1∑x2∑x3p(x1∣x2,x3)∣3=f(2)1∣x3=f(x2)p(x2)log⁡p(x1,x3∣x2)H(1\mid23)\to-\left.\sum_{x_1}\sum_{x_2}\sum_{x_3}p(x_1\mid x_2,x_3)\right|_{3=f(2)}\left.1\right|_{x_3=f(x_2)}p(x_2)\log p(x_1,x_3\mid x_2)
=−∑x1∑x2p(x1∣x2)p(x2)log⁡p(x1∣x2)=−∑x1∑x2p(x1,x2)log⁡p(x1∣x2)≔H(1∣2)(17)\begin{aligned} &=-\sum_{x_1}\sum_{x_2}p(x_1\mid x_2)p(x_2)\log p(x_1\mid x_2) =-\sum_{x_1}\sum_{x_2}p(x_1,x_2)\log p(x_1\mid x_2)\coloneqq H(1\mid2) \tag*{(17)} \end{aligned}

∴H(1∣32)→3=f(2)H(1∣2)\therefore H(1\mid32)\xrightarrow{3=f(2)}H(1\mid2)

References

  1. [1]T. M. Cover and J. A. Thomas, Elements of Information Theory John Wiley & Sons, New York (1991).
  2. [2]P. von Platen, Medium. How to generate text: using different decoding methods for language generation with Transformers, Retrieved from https://huggingface.co/blog/how-to-generate
  3. [3]D. Edge, H. Trinh, N. Chang, J. Bradley, A. Chao, A. Mody, S. Truitt, J. Larson. From Local to Global: A Graph RAG Approach to Query-Focused Summarization. arXiv: 2404.16130v1 [cs.CL].arxiv.org/abs/2404.16130
  4. [4]R. Dalimunthe, Medium. Towards Data Science, Retrieved from https://towardsdatascience.com/an-easy-way-to-comprehend-how-graphrag-works-6d53f8b540d0
  5. [5]P. Zhao, H. Zhang, Q. Yu, Z. Wang, Y. Geng, F. Fu, L. Yang, W. Zhang, J. Jiang, B. Cui, Retrieval-Augmented Generation for AI-Generated Content: A Survey, arXiv:2402.19473v6 [cs.CV].arxiv.org/abs/2402.19473

Paper details

vlnc:W_pywrvmmj
v1 · latestHistory (1)

published · Fresh — added to the Hub within the last 30 days

added ·

Usage

views · 9

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

CC BY 4.0

Original source

  • Computer Science

Not recorded for this paper · View statement →

Looking for related papers…
Contents