Repository: gradio-app/gradio

Issue:
It is unclear what the api of the custom interpretation function should be
### Describe the bug

The `Interface` docs say that the `interpretation` parameter can be "your own custom interpretation function.". However, it's not clear to me what the api of that function should be.

There's an example in the `advanced_interface_features` guide but it doesn't work when I run it locally. After hitting "Interpret" it just hangs there:

```python
import re

import gradio as gr

male_words, female_words = ["he", "his", "him"], ["she", "hers", "her"]

def gender_of_sentence(sentence):
    male_count = len([word for word in sentence.split() if word.lower() in male_words])
    female_count = len(
        [word for word in sentence.split() if word.lower() in female_words]
    )
    total = max(male_count + female_count, 1)
    return {"male": male_count / total, "female": female_count / total}

def interpret_gender(sentence):
    result = gender_of_sentence(sentence)
    is_male = result["male"] > result["female"]
    interpretation = []
    for word in re.split("( )", sentence):
        score = 0
        token = word.lower()
        if (is_male and token in male_words) or (not is_male and token in female_words):
            score = 1
        elif (is_male and token in female_words) or (
            not is_male and token in male_words
        ):
            score = -1
        interpretation.append((word, score))
    return interpretation

demo = gr.Interface(
    fn=gender_of_sentence,
    inputs=gr.Textbox(value="She went to his house to get her keys."),
    outputs="label",
    interpretation=interpret_gender,
)

demo.launch()
```

![interpretation_bug](https://user-images.githubusercontent.com/41651716/176301559-33fe07b9-115b-4f2c-aa7f-3716cc281e00.gif)



### Is there an existing issue for this?

- [X] I have searched the existing issues

### Reproduction

Run the demo above.

### Screenshot

_No response_

### Logs

Looking at the api response in this case, looks like we're returning `["She",1]` but judging from the response of "default" interpretation, we should be returning a list of lists.



### System Info

```shell
-
```


### Severity

serious, but I can work around it


Discussion:
This is both a docs and a bug issue since the example doesn't work and the docs are not very clear so adding it to the docs milestone. 

Resolving patch:
diff --git a/demo/gender_sentence_custom_interpretation/run.py b/demo/gender_sentence_custom_interpretation/run.py
--- a/demo/gender_sentence_custom_interpretation/run.py
+++ b/demo/gender_sentence_custom_interpretation/run.py
@@ -14,6 +14,8 @@ def gender_of_sentence(sentence):
     return {"male": male_count / total, "female": female_count / total}
 
 
+# Number of arguments to interpretation function must
+# match number of inputs to prediction function
 def interpret_gender(sentence):
     result = gender_of_sentence(sentence)
     is_male = result["male"] > result["female"]
@@ -28,7 +30,9 @@ def interpret_gender(sentence):
         ):
             score = -1
         interpretation.append((word, score))
-    return interpretation
+    # Output must be a list of lists containing the same number of elements as inputs
+    # Each element corresponds to the interpretation scores for the given input
+    return [interpretation]
 
 
 demo = gr.Interface(
diff --git a/gradio/interface.py b/gradio/interface.py
--- a/gradio/interface.py
+++ b/gradio/interface.py
@@ -160,7 +160,7 @@ def __init__(
             cache_examples: If True, caches examples in the server for fast runtime in examples. The default option in HuggingFace Spaces is True. The default option elsewhere is False.
             examples_per_page: If examples are provided, how many to display per page.
             live: whether the interface should automatically rerun if any of the inputs change.
-            interpretation: function that provides interpretation explaining prediction output. Pass "default" to use simple built-in interpreter, "shap" to use a built-in shapley-based interpreter, or your own custom interpretation function.
+            interpretation: function that provides interpretation explaining prediction output. Pass "default" to use simple built-in interpreter, "shap" to use a built-in shapley-based interpreter, or your own custom interpretation function. For more information on the different interpretation methods, see the Advanced Interface Features guide.
             num_shap: a multiplier that determines how many examples are computed for shap-based interpretation. Increasing this value will increase shap runtime, but improve results. Only applies if interpretation is "shap".
             title: a title for the interface; if provided, appears above the input and output components in large font. Also used as the tab title when opened in a browser window.
             description: a description for the interface; if provided, appears above the input and output components and beneath the title in regular font. Accepts Markdown and HTML content.


Test patch: