Programming language detection is a common need in the analysis of large source code bases. It is supported by a number of existing tools that rely on several features, and most notably file extensions, to determine file types. We consider the problem of accurately detecting the type of files commonly found in software code bases, based solely on textual file content. Doing so is helpful to classify source code that lack file extensions (e.g., code snippets posted on the Web or executable scripts), to avoid misclassifying source code that has been recorded with wrong or uncommon file extensions, and also shed some light on the intrinsic recognizability of source code files. We propose a simple model that (a) use a language-agnostic word tokenizer for textual files, (b) group tokens in 1-/2-grams, (c) build feature vectors based on N-gram frequencies, and (d) use a simple fully connected neural network as classifier. As training set we use textual files extracted from GitHub repositories with at least 1000 stars, using existing file extensions as ground truth. Despite its simplicity the proposed model reaches ≈ 85% in our experiments for a relatively high number of recognized classes (more than 130 file types).

Content-Based Textual File Type Detection at Scale / Del Bonifro F.; Gabbrielli M.; Zacchiroli S.. - ELETTRONICO. - (2021), pp. 3457756.485-3457756.492. (Intervento presentato al convegno 2021 13th International Conference on Machine Learning and Computing, ICMLC 2021 tenutosi a chn nel 2021) [10.1145/3457682.3457756].

Content-Based Textual File Type Detection at Scale

Del Bonifro F.;Gabbrielli M.;Zacchiroli S.
2021

Abstract

Programming language detection is a common need in the analysis of large source code bases. It is supported by a number of existing tools that rely on several features, and most notably file extensions, to determine file types. We consider the problem of accurately detecting the type of files commonly found in software code bases, based solely on textual file content. Doing so is helpful to classify source code that lack file extensions (e.g., code snippets posted on the Web or executable scripts), to avoid misclassifying source code that has been recorded with wrong or uncommon file extensions, and also shed some light on the intrinsic recognizability of source code files. We propose a simple model that (a) use a language-agnostic word tokenizer for textual files, (b) group tokens in 1-/2-grams, (c) build feature vectors based on N-gram frequencies, and (d) use a simple fully connected neural network as classifier. As training set we use textual files extracted from GitHub repositories with at least 1000 stars, using existing file extensions as ground truth. Despite its simplicity the proposed model reaches ≈ 85% in our experiments for a relatively high number of recognized classes (more than 130 file types).
2021
ACM International Conference Proceeding Series
485
492
Content-Based Textual File Type Detection at Scale / Del Bonifro F.; Gabbrielli M.; Zacchiroli S.. - ELETTRONICO. - (2021), pp. 3457756.485-3457756.492. (Intervento presentato al convegno 2021 13th International Conference on Machine Learning and Computing, ICMLC 2021 tenutosi a chn nel 2021) [10.1145/3457682.3457756].
Del Bonifro F.; Gabbrielli M.; Zacchiroli S.
File in questo prodotto:
File Dimensione Formato  
2101.08508.pdf

accesso aperto

Tipo: Postprint
Licenza: Licenza per accesso libero gratuito
Dimensione 774.93 kB
Formato Adobe PDF
774.93 kB Adobe PDF Visualizza/Apri

I documenti in IRIS sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.

Utilizza questo identificativo per citare o creare un link a questo documento: https://hdl.handle.net/11585/876867
Citazioni
  • ???jsp.display-item.citation.pmc??? ND
  • Scopus 2
  • ???jsp.display-item.citation.isi??? ND
social impact