@@ -11,6 +11,9 @@ about its predictions:
1111
1212 LLM token probabilities visualized with eli5.explain_prediction
1313
14+ 1. OpenAI models
15+ ----------------
16+
1417To follow this tutorial you need the ``openai `` library installed and
1518working.
1619
@@ -64,10 +67,10 @@ properties from a free-form product description:
6467 json
6568 {
6669 "materials": ["metal"],
67- "type": "table lamp ",
70+ "type": "task lighting ",
6871 "color": "silky matte grey",
6972 "price": 150.00,
70- "summary": "Stay is a flexible and elegant table lamp designed by Maria Berntsen ."
73+ "summary": "Stay table lamp with adjustable arm and head for optimal task lighting ."
7174 }
7275
7376
@@ -311,8 +314,8 @@ We can obtain the original prediction from the explanation object via
311314``explanation.targets[0].target.message.content `` to get the prediction
312315text.
313316
314- Limitations
315- -----------
317+ 2. Limitations
318+ --------------
316319
317320Even though above the model confidence matched our expectations, it’s
318321not always the case. For example, if we use “Chain of Thought”
@@ -531,6 +534,121 @@ temperatures:
531534
532535
533536
537+
538+
539+
540+
541+
542+
543+
544+
545+
546+
547+
548+
549+
550+
551+
552+
553+
554+
555+
556+
557+
558+ 3. Open Source and other models
559+ -------------------------------
560+
561+ If an API endpoint can provide ``logprobs `` in the right format, then it
562+ should work. However few APIs or libraries do provide it, even for open
563+ source models. One library which is know to work is ``mlx_lm `` (Mac OS
564+ only), e.g. if you start the server like this:
565+
566+ ::
567+
568+ mlx_lm.server --model mlx-community/Mistral-7B-Instruct-v0.3-4bit
569+
570+ Then you can explain predictions with a custom client:
571+
572+ .. code :: ipython3
573+
574+ client_custom = openai.OpenAI(base_url="http://localhost:8080/v1", api_key="dummy")
575+ eli5.explain_prediction(
576+ client_custom,
577+ prompt + ' Price should never be zero.',
578+ model="mlx-community/Mistral-7B-Instruct-v0.3-4bit",
579+ )
580+
581+
582+
583+
584+ .. raw :: html
585+
586+
587+ <style >
588+ table .eli5-weights tr :hover {
589+ filter : brightness (85% );
590+ }
591+ </style >
592+
593+
594+
595+
596+
597+
598+
599+
600+
601+
602+
603+
604+
605+
606+
607+
608+
609+
610+
611+
612+
613+
614+
615+
616+
617+
618+
619+
620+
621+
622+
623+
624+ <p style =" margin-bottom : 2.5em ; margin-top :0 ; white-space : pre-wrap ;" ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" >{
625+ </span ><span style =" background-color : hsl (102.26933456703064 , 100.00% , 50.00% )" title =" 0.969" > </span ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" > " ; materials" ; : [" ; </span ><span style =" background-color : hsl (94.45469472360817 , 100.00% , 50.00% )" title =" 0.925" >sil</span ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" >ky matte grey metal</span ><span style =" background-color : hsl (106.55663140845363 , 100.00% , 50.00% )" title =" 0.984" >" ; ],</span ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" >
626+ " ; type" ; :</span ><span style =" background-color : hsl (67.65625435391846 , 100.00% , 50.00% )" title =" 0.616" > " ; </span ><span style =" background-color : hsl (54.98115667185111 , 100.00% , 50.00% )" title =" 0.423" >Not</span ><span style =" background-color : hsl (99.15673841086969 , 100.00% , 50.00% )" title =" 0.954" > specified</span ><span style =" background-color : hsl (60.184714790030306 , 100.00% , 50.00% )" title =" 0.503" > in</span ><span style =" background-color : hsl (89.21337460784397 , 100.00% , 50.00% )" title =" 0.882" > the</span ><span style =" background-color : hsl (78.55493818915068 , 100.00% , 50.00% )" title =" 0.767" > description</span ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" >" ; ,
627+ " ; color" ; : " ; </span ><span style =" background-color : hsl (75.83477075768666 , 100.00% , 50.00% )" title =" 0.732" >Not</span ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" > specified in the description" ; ,
628+ " ; price" ; :</span ><span style =" background-color : hsl (106.55663140845363 , 100.00% , 50.00% )" title =" 0.984" > </span ><span style =" background-color : hsl (66.38465137200743 , 100.00% , 50.00% )" title =" 0.597" >9</span ><span style =" background-color : hsl (120.0 , 100.00% , 50.00% )" title =" 1.000" >9.99,</span ><span style =" background-color : hsl (70.37163543696023 , 100.00% , 50.00% )" title =" 0.656" >
629+ </span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000"> "summary": "</span><span style="background-color: hsl(87.74310691905805, 100.00%, 50.00%)" title="0.869">St</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000">ay</span><span style="background-color: hsl(96.62538179271525, 100.00%, 50.00%)" title="0.939"> is</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000"> a</span><span style="background-color: hsl(50.86740763861728, 100.00%, 50.00%)" title="0.362"> flexible</span><span style="background-color: hsl(74.98611970505678, 100.00%, 50.00%)" title="0.720"> and</span><span style="background-color: hsl(53.693017832784676, 100.00%, 50.00%)" title="0.404"> beautiful</span><span style="background-color: hsl(86.3702071513559, 100.00%, 50.00%)" title="0.855"> Dan</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000">ish</span><span style="background-color: hsl(78.55493818915068, 100.00%, 50.00%)" title="0.767">-</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000">designed</span><span style="background-color: hsl(83.859705332877, 100.00%, 50.00%)" title="0.829"> table</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000"> lamp</span><span style="background-color: hsl(83.859705332877, 100.00%, 50.00%)" title="0.829"> with</span><span style="background-color: hsl(63.98782501663244, 100.00%, 50.00%)" title="0.561"> a</span><span style="background-color: hsl(57.717412015697704, 100.00%, 50.00%)" title="0.465"> discre</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000">et</span><span style="background-color: hsl(102.26933456703064, 100.00%, 50.00%)" title="0.969"> switch</span><span style="background-color: hsl(73.36326933304912, 100.00%, 50.00%)" title="0.698"> and</span><span style="background-color: hsl(52.049284214496396, 100.00%, 50.00%)" title="0.380"> adjust</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000">able</span><span style="background-color: hsl(68.98323009885026, 100.00%, 50.00%)" title="0.636"> arm</span><span style="background-color: hsl(90.80119410884282, 100.00%, 50.00%)" title="0.896"> and</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000"> head</span><span style="background-color: hsl(78.55493818915068, 100.00%, 50.00%)" title="0.767">,</span><span style="background-color: hsl(65.7679832651431, 100.00%, 50.00%)" title="0.588"> ideal</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000"> for</span><span style="background-color: hsl(69.66933255201431, 100.00%, 50.00%)" title="0.646"> office</span><span style="background-color: hsl(106.55663140845363, 100.00%, 50.00%)" title="0.984"> task</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000"> lighting</span><span style="background-color: hsl(102.26933456703064, 100.00%, 50.00%)" title="0.969">."</span><span style="background-color: hsl(120.0, 100.00%, 50.00%)" title="1.000">
630+ }</span ></p >
631+
632+
633+
634+
635+
636+
637+
638+
639+
640+
641+
642+
643+
644+
645+
646+
647+
648+
649+
650+
651+
534652
535653
536654
0 commit comments