In order to explore the internal coupling relationship of the influencing factors of traffic accident duration and reveal the mechanism of text information in the chain transmission process, a keyword importance analysis method based on word frequency-inverse text frequency (TF-IDF) model was proposed by using natural language processing technology and random forest algorithm. At the same time, a multiple mediating effect model of highway traffic accident duration is established, and the Bootstrap sampling method of product coefficient was used to test the mediating effect. The significance of text features in parallel mediating path and two-level chain mediating path was tested respectively, and the strength of mediating effect was calculated. Taking 3 046 traffic accident records of expressways in Shanxi Province as an example, the results showed that in the influence path of duration, there is a partial chain mediating relationship between accident type and month, and the mediating effect accounts for 11.868%. There is a complete chain mediating relationship between accident type and weather, location and accident range, and the mediating effect accounts for 100%. The number of characters and the number of reports are significant mediating variables in the specific path. The number of reports is completely mediated by the type of mediating effect of the weather on the duration. The number of characters is completely mediated by the type of mediating effect of the accident range on the duration. The impact of the period on the duration is 7.075% through the number of characters. The two-level chain mediating path of specific keyword sets exists.