File size: 7,502 Bytes
de86128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import streamlit as st
import pandas as pd
from datasets import load_dataset
from ast import literal_eval
import altair as alt

nlp_tasks = ["text-classification", "text-generation", "text2text-generation", "token-classification", "fill-mask", "question-answering"
             "translation", "conversational", "sentence-similarity", "summarization", "multiple-choice", "zero-shot-classification", "table-question-answering"
]
audio_tasks = ["automatic-speech-recognition", "audio-classification", "text-to-speech", "audio-to-audio", "voice-activity-detection"]
cv_tasks = ["image-classification", "image-segmentation", "zero-shot-image-classification", "image-to-image", "unconditional-image-generation", "object-detection"]
multimodal = ["feature-extraction", "text-to-image", "visual-question-answering", "image-to-text", "document-question-answering"]
tabular = ["tabular-clasification", "tabular-regression"]

modalities = {
    "nlp": nlp_tasks,
    "audio": audio_tasks,
    "cv": cv_tasks,
    "multimodal": multimodal,
    "tabular": tabular,
    "rl": ["reinforcement-learning"]
}

def modality(row):
  pipeline = row["pipeline"]
  for modality, tasks in modalities.items():
    if pipeline in tasks:
      return modality
  if type(pipeline) == "str":
    return "unk_modality"
  return None

supported_revisions = ["27_09_22"]

def process_dataset(version):
    # Load dataset at specified revision
    dataset = load_dataset("open-source-metrics/model-repos-stats", revision=version)

    # Convert to pandas dataframe
    data = dataset["train"].to_pandas()

    # Add modality column
    data["modality"] = data.apply(modality, axis=1)

    # Bin the model card length into some bins
    data["length_bins"] = pd.cut(data["text_length"], [0, 200, 1000, 2000, 3000, 4000, 5000, 7500, 10000, 20000, 50000])

    return data

base = st.selectbox(
    'What revision do you want to use',
    supported_revisions)
data = process_dataset(base)

total_samples = data.shape[0]
st.metric(label="Total models", value=total_samples)

tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["Language", "License", "Pipeline", "Discussion Features", "Libraries", "Model Cards", "Super users"])

with tab1:
    st.header("Languages info")

    data.loc[data.languages == "False", 'languages'] = None
    data.loc[data.languages == {}, 'languages'] = None

    no_lang_count = data["languages"].isna().sum()
    data["languages"] = data["languages"].fillna('none')

    def make_list(row):
        languages = row["languages"]
        if languages == "none":
            return []
        return literal_eval(languages)

    def language_count(row):
        languages = row["languages"]
        leng = len(languages)
        return leng

    data["languages"] = data.apply(make_list, axis=1)
    data["repos_count"] = data.apply(language_count, axis=1)

    models_with_langs = data[data["repos_count"] > 0]
    langs = models_with_langs["languages"].explode()
    langs = langs[langs != {}]
    total_langs = len(langs.unique())

    col1, col2, col3 = st.columns(3)
    with col1:
        st.metric(label="Language Specified", value=total_samples-no_lang_count)
    with col2:
        st.metric(label="No Language Specified", value=no_lang_count)
    with col3:
        st.metric(label="Total Unique Languages", value=total_langs)

    st.subheader("Distribution of languages per model repo")
    linguality = st.selectbox(
        'All or just Multilingual',
        ["All", "Just Multilingual", "Three or more languages"])

    filter = 0
    if linguality == "Just Multilingual":
        filter = 1
    elif linguality == "Three or more languages":
        filter = 2

    models_with_langs = data[data["repos_count"] > filter]
    df1 = models_with_langs['repos_count'].value_counts()
    st.bar_chart(df1)

    st.subheader("Distribution of repos per language")
    linguality_2 = st.selectbox(
        'All or filtered',
        ["All", "No English", "Remove top 10"])

    filter = 0
    if linguality_2 == "All":
        filter = 0
    elif linguality_2 == "No English":
        filter = 1
    else:
        filter = 2

    models_with_langs = data[data["repos_count"] > 0]
    langs = models_with_langs["languages"].explode()
    langs = langs[langs != {}]

    d = langs.value_counts().rename_axis("language").to_frame('counts').reset_index()
    if filter == 1:
        d = d.iloc[1:]
    elif filter == 2:
        d = d.iloc[10:]

    # Just keep top 25 to avoid vertical scroll
    d = d.iloc[:25]

    st.write(alt.Chart(d).mark_bar().encode(
        x='counts',
        y=alt.X('language', sort=None)
    ))

    st.subheader("Raw Data")
    col1, col2 = st.columns(2)
    with col1:
        st.dataframe(df1)
    with col2:
        d = langs.value_counts().rename_axis("language").to_frame('counts').reset_index()
        st.dataframe(d)
    
    

with tab2:
    st.header("License info")

    no_license_count = data["license"].isna().sum()
    col1, col2, col3 = st.columns(3)
    with col1:
        st.metric(label="License Specified", value=total_samples-no_license_count)
    with col2:
        st.metric(label="No license Specified", value=no_license_count)
    with col3:
        st.metric(label="Total Unique Licenses", value=len(data["license"].unique()))

    st.subheader("Distribution of licenses per model repo")
    license_filter = st.selectbox(
        'All or filtered',
        ["All", "No Apache 2.0", "Remove top 10"])

    filter = 0
    if license_filter == "All":
        filter = 0
    elif license_filter == "No Apache 2.0":
        filter = 1
    else:
        filter = 2

    d = data["license"].value_counts().rename_axis("license").to_frame('counts').reset_index()
    if filter == 1:
        d = d.iloc[1:]
    elif filter == 2:
        d = d.iloc[10:]

    # Just keep top 25 to avoid vertical scroll
    d = d.iloc[:25]

    st.write(alt.Chart(d).mark_bar().encode(
        x='counts',
        y=alt.X('license', sort=None)
    ))
    st.text("There are some edge cases, as old repos using lists of licenses. We are working on fixing this.")

    
    st.subheader("Raw Data")
    d = data["license"].value_counts().rename_axis("license").to_frame('counts').reset_index()
    st.dataframe(d)
    
with tab3:
    st.header("Pipeline info")

    no_pipeline_count = data["pipeline"].isna().sum()
    col1, col2, col3 = st.columns(3)
    with col1:
        st.metric(label="Pipeline Specified", value=total_samples-no_pipeline_count)
    with col2:
        st.metric(label="No pipeline Specified", value=no_pipeline_count)
    with col3:
        st.metric(label="Total Unique Pipelines", value=len(data["pipeline"].unique()))

    st.subheader("Distribution of pipelines per model repo")
    pipeline_filter = st.selectbox(
        'All or filtered',
        ["All", "NLP", "CV", "Audio", "RL", "Multimodal", "Tabular"])

    filter = 0
    if pipeline_filter == "All":
        filter = 0
    elif pipeline_filter == "NLP":
        filter = 1
    elif pipeline_filter == "CV":
        filter = 2
    elif pipeline_filter == "Audio":
        filter = 3
    elif pipeline_filter == "RL":
        filter = 4
    elif pipeline_filter == "Multimodal":
        filter = 5
    elif pipeline_filter == "Tabular":
        filter = 6

    d = data["pipeline"].value_counts().rename_axis("pipeline").to_frame('counts').reset_index()

    st.write(alt.Chart(d).mark_bar().encode(
        x='counts',
        y=alt.X('pipeline', sort=None)
    ))